假设我们有一个对话框,其中有一行用户更改的参数
这些参数之间有一些联系。用户可以根据需要多次使用“添加类型”按钮添加行。目的是在单击按钮时复制整行小部件,保存小部件之间的连接,并有机会访问此参数(在本例中,打印第二行编辑的文本,包括解释器中新行中的文本)
请帮助我的功能添加\u行
import sys
from PyQt5 import QtWidgets
from dialog_1 import Ui_Form
class Dialog(QtWidgets.QDialog):
def __init__(self):
super().__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
self.ui.comboBox.addItems(['123','456','qwerty'])
self.ui.comboBox.activated.connect(lambda: self.ui.lineEdit1.setText(self.ui.comboBox.currentText()))
self.ui.lineEdit2.returnPressed.connect(lambda: print(self.ui.lineEdit2.text()))
self.ui.pushButton.clicked.connect(self.add_row)
def add_row(self):
pass
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
main = Dialog()
main.show()
sys.exit(app.exec_())
对话框\u 1.py文件:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(774, 169)
self.frame = QtWidgets.QFrame(Form)
self.frame.setGeometry(QtCore.QRect(0, 0, 661, 61))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(100)
sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
self.frame.setSizePolicy(sizePolicy)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.gridLayout_5 = QtWidgets.QGridLayout(self.frame)
self.gridLayout_5.setObjectName("gridLayout_5")
self.pushButton2 = QtWidgets.QPushButton(self.frame)
self.pushButton2.setObjectName("pushButton2")
self.gridLayout_5.addWidget(self.pushButton2, 0, 4, 1, 1)
self.label = QtWidgets.QLabel(self.frame)
self.label.setObjectName("label")
self.gridLayout_5.addWidget(self.label, 0, 0, 1, 1)
self.comboBox = QtWidgets.QComboBox(self.frame)
self.comboBox.setObjectName("comboBox")
self.gridLayout_5.addWidget(self.comboBox, 0, 5, 1, 1)
self.checkBox = QtWidgets.QCheckBox(self.frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.checkBox.sizePolicy().hasHeightForWidth())
self.checkBox.setSizePolicy(sizePolicy)
self.checkBox.setLayoutDirection(QtCore.Qt.LeftToRight)
self.checkBox.setText("")
self.checkBox.setAutoRepeat(False)
self.checkBox.setObjectName("checkBox")
self.gridLayout_5.addWidget(self.checkBox, 0, 6, 1, 1)
self.lineEdit1 = QtWidgets.QLineEdit(self.frame)
self.lineEdit1.setObjectName("lineEdit1")
self.gridLayout_5.addWidget(self.lineEdit1, 0, 1, 1, 1)
self.lineEdit2 = QtWidgets.QLineEdit(self.frame)
self.lineEdit2.setObjectName("lineEdit2")
self.gridLayout_5.addWidget(self.lineEdit2, 0, 8, 1, 1)
self.pushButton1 = QtWidgets.QPushButton(self.frame)
self.pushButton1.setObjectName("pushButton1")
self.gridLayout_5.addWidget(self.pushButton1, 0, 9, 1, 1)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(680, 20, 75, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton2.setText(_translate("Form", "..."))
self.label.setText(_translate("Form", "#1"))
self.pushButton1.setText(_translate("Form", "..."))
self.pushButton.setText(_translate("Form", "Add Type"))enter code here
我想你可以用这个达到你想要的。它只是需要一些调整才能正常工作,但我不能这样做,因为我没有
.ui
文件我已成功使用此代码:
最后一件事仍然不清楚: 例如,如果我需要将一个文本从行中的lineEdit2#3复制到行外的其他行编辑,该怎么办Dialog with lineEdit3
我应该放什么来代替“??”
相关问题 更多 >
编程相关推荐