gpt4 book ai didi

python - Pyqt4 - 将 2 个组合框的值添加到文本编辑中

转载 作者:行者123 更新时间:2023-12-01 05:51:47 26 4
gpt4 key购买 nike

我需要帮助将 2 个组合框的值添加到同一个 QTextEdit 中。这是我的代码的一部分:

    self.pushButton2 = QtGui.QPushButton(self)
self.pushButton2.setGeometry(QtCore.QRect(520, 950, 98, 27))
self.pushButton2.setObjectName(_fromUtf8('botao2'))
self.comboBox = QtGui.QComboBox(self)
self.comboBox.setGeometry(QtCore.QRect(920, 850, 111, 27))
self.comboBox.setObjectName(_fromUtf8("comboBox"))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox.addItem(_fromUtf8(""))
self.comboBox_2 = QtGui.QComboBox(self)
self.comboBox_2.setGeometry(QtCore.QRect(920, 950, 78, 27))
self.comboBox_2.setObjectName(_fromUtf8("comboBox_2"))
self.comboBox_2.addItem(_fromUtf8(""))
self.comboBox_2.addItem(_fromUtf8(""))
self.comboBox_2.addItem(_fromUtf8(""))
self.text2 = QtGui.QTextEdit(self)
self.text2.setGeometry(QtCore.QRect(250,700, 500, 200))
self.text2.setObjectName(_fromUtf8("textEdit"))
QtCore.QObject.connect(self.comboBox, QtCore.SIGNAL(_fromUtf8("activated(QString)")), self.text2.append)
QtCore.QObject.connect(self.comboBox_2, QtCore.SIGNAL(_fromUtf8("activated(QString)")), self.text2.append)
QtCore.QMetaObject.connectSlotsByName(self)
self.comboBox.setItemText(0, QtGui.QApplication.translate("MainWindow", "Narrador", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.setItemText(1, QtGui.QApplication.translate("MainWindow", "Filme", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.setItemText(2, QtGui.QApplication.translate("MainWindow", "Ator", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.setItemText(3, QtGui.QApplication.translate("MainWindow", "Genero", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox_2.setItemText(0, QtGui.QApplication.translate("MainWindow", "-1", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox_2.setItemText(1, QtGui.QApplication.translate("MainWindow", "1", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox_2.setItemText(2, QtGui.QApplication.translate("MainWindow", "0", None, QtGui.QApplication.UnicodeUTF8))

我需要在QTextEdit(我的text2)的同一行中显示此组合框的值,例如:

combobox = I selected "Genero"
combobox_2 = I selected "0"

当我按下一个简单的按钮时,我想在文本2的同一行中显示:“Genero,0”。

我该怎么做?我需要连接这些组合框吗?我怎样才能做到呢?

最佳答案

您需要为信号 clicked 创建一个槽QPushButton的这会在您的 QTextEdit 中添加一行与您的值 QComboxBox es,像这样:

    self.pushButton2.clicked.connect(self.on_pushButton2_clicked)

def on_pushButton2_clicked(self):
text1 = self.comboBox_1.currentText()
text2 = self.comboBox_2.currentText()
self.text2.append("{0},{1}".format(text1, text2))

关于python - Pyqt4 - 将 2 个组合框的值添加到文本编辑中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13995182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com