本文介绍了将 lineEdit 值设置为另一个类中的标签(Pyqt4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Qt 新手,想将 entry/lineEdit 字段值设置为在另一个类中定义的另一个框架中可用的标签:

I am new to Qt want to set an entry/lineEdit field value to a Label available in another frame which is defined in another class:

from PyQt4 import QtCore, QtGui
import time
from PyQt4.QtCore import SIGNAL
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)


class Ui_Dialog1(object):
    def setupUi(self, Dialog):
        self.frame = QtGui.QFrame(Dialog)
        self.frame.setGeometry(QtCore.QRect(40, 20, 311, 391))
        self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtGui.QFrame.Raised)
        self.frame.setObjectName(_fromUtf8("frame"))
        self.label = QtGui.QLabel(self.frame)
        self.label.setGeometry(QtCore.QRect(120, 180, 72, 23))
        self.label.setObjectName(_fromUtf8("label"))
        self.label.setText(_translate("Dialog", "omniOS", None))
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(391, 437)
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))



class Ui_Dialog2(object):
    def setupUi(self, Dialog):
        self.frame_2 = QtGui.QFrame(Dialog)
        self.frame_2.setGeometry(QtCore.QRect(30, 30, 311, 391))
        self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_2.setObjectName(_fromUtf8("frame_2"))
        self.label_2 = QtGui.QLabel(self.frame_2)
        self.label_2.setGeometry(QtCore.QRect(50, 230, 72, 31))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.lineEdit = QtGui.QLineEdit(self.frame_2)
        self.lineEdit.setGeometry(QtCore.QRect(150, 230, 113, 33))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.label_2.setText(_translate("Dialog", "Login", None))
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(391, 437)
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
        self.retranslateUi(Dialog)


        self.pb = QtGui.QPushButton(self.frame_2)
        self.pb.setObjectName(_fromUtf8("login"))
        self.pb.setText("Login")
        self.connect(self.pb, SIGNAL("clicked()"), self.button_click)

    def button_click(self):
        # shost is a QString object
        text = self.lineEdit.text()
        print (text)


    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))


class Ui_Dialog3(object):
    def setupUi(self, Dialog):
        self.frame_3 = QtGui.QFrame(Dialog)
        self.frame_3.setGeometry(QtCore.QRect(30, 30, 311, 391))
        self.frame_3.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_3.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_3.setObjectName(_fromUtf8("frame_3"))
        self.label_3 = QtGui.QLabel(self.frame_3)
        self.label_3.setGeometry(QtCore.QRect(50, 230, 72, 31))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_4 = QtGui.QLabel(self.frame_3)
        self.label_4.setGeometry(QtCore.QRect(150, 230, 113, 33))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_3.setText(_translate("Dialog", "Email", None))
        self.label_4.setText(_translate("Dialog", text, None))

        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(391, 437)
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
        self.retranslateUi(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))




class Dialog1(QtGui.QDialog, Ui_Dialog1):
    def __init__(self, parent=None):
        super(Dialog1, self).__init__(parent)
        self.setupUi(self)


class Dialog2(QtGui.QDialog, Ui_Dialog2):
    def __init__(self, parent=None):
        super(Dialog2, self).__init__(parent)
        self.setupUi(self)


class Dialog3(QtGui.QDialog, Ui_Dialog3):
    def __init__(self, parent=None):
        super(Dialog3, self).__init__(parent)
        self.setupUi(self)



if __name__=="__main__":
    import sys
    a = QtGui.QApplication(sys.argv)
    w1 = Dialog1()
    w2 = Dialog2()
    w3 = Dialog3()

    def on_timeout():
        w1.hide()
        w2.show()
    def on_timeout1():
        w2.hide()
        w3.show()


    w1.show()
    QtCore.QTimer.singleShot(3000, on_timeout)
    QtCore.QTimer.singleShot(6000, on_timeout1)

    sys.exit(a.exec_())

我需要做的是将用户输入的lineEdit(在Dialog2类中)值设置为label_4(在label_4类中)code>Dialog3):

What I need to do is to set the lineEdit (in class Dialog2) value entered by the user to label_4 (in class Dialog3):

def button_click(self):
    # shost is a QString object
    text = self.lineEdit.text()
    print (text)

问题:如何在用户输入电子邮件后更新 Dialog3.label_4?

Question: How can I update Dialog3.label_4 after the user inputs the email?

推荐答案

更改on_timeout1"函数

Change the "on_timeout1" function

def on_timeout1():
    w2.hide()
    w3.show()
    w3.label_4.setText(w2.lineEdit.text())

这篇关于将 lineEdit 值设置为另一个类中的标签(Pyqt4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 03:34