Python Qt Designer用于创建后续文本条目的按钮

时间:2015-03-16 19:57:57

标签: windows qt python-2.7 widget

我试图在Qt Designer中创建一个GUI,它有一个文本输入框和一个按钮,在第一个下面插入另一个文本输入框。我可能需要做十几次或更多次。

这是我在Qt Designer中的示例代码:

from PySide import QtCore, QtGui

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(247, 300)
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(110, 10, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.lineEdit1 = QtGui.QLineEdit(Dialog)
        self.lineEdit1.setGeometry(QtCore.QRect(20, 10, 31, 20))
        self.lineEdit1.setObjectName("lineEdit1")
        self.lineEdit2 = QtGui.QLineEdit(Dialog)
        self.lineEdit2.setGeometry(QtCore.QRect(60, 10, 31, 20))
        self.lineEdit2.setObjectName("lineEdit2")

        self.retranslateUi(Dialog)
        # QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), Dialog.add_wells) #
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "PushButton", None, QtGui.QApplication.UnicodeUTF8))

这是运行GUI的代码:

from PySide.QtGui import *
from PySide.QtCore import *
import sys

import addentryexample


class MainWindow(QDialog, addentryexample.Ui_Dialog):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)

        self.connect(self.pushButton, SIGNAL("clicked()"), self.add_entry)

    def add_entry(self):

        pass



app = QApplication(sys.argv)
form = MainWindow()
form.show()
app.exec_()

我正在努力研究如何迭代文本框条目的每个名称,以便稍后我可以从中选择值。我认为放置它们应该只需要为每个“几何”添加一定量的数据。属性。

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您可以使用findChildren

lineEdits = form.findChildren(QLineEdit)
for lineEdit in lineEdits:
    print lineEdit.objectName()