【发布时间】:2021-03-13 09:50:18
【问题描述】:
我有一个QDialog,其中有几个QLineEdits,还有一个包含3 个条目的下拉列表(QComboBox):通过、通过附加cmets 和失败。
每当用户选择“失败”或“通过额外的 cmets”时,我都会添加一个额外的 QLineEdit 以供评论。如果选择“通过”,则不会添加任何字段。
我设法在通过在开始时的字段中未显示的情况下选择了两个条目之一时,我设法实现了额外的注释字段的一部分,并且只要在输入所选择的条目时,它会变得可见,但我不设法只要选择“通过”,字段就会再次消失。
这里有一些与它有关的sn-ps:
self.resultLabel = QLabel("Result:", self)
#define dropdown
self.resultCombo = QComboBox(self)
self.resultCombo.addItem("passed")
self.resultCombo.addItem("passed with additional comments")
self.resultCombo.addItem("failed")
#define the extra comment label and input field
self.extraCommentLabel = QLabel("Comment",self)
self.extraCommentLabel.setVisible(False)
self.extraCommentLine = QLineEdit(self)
self.extraCommentLine.setVisible(False)
self.resultCombo.currentIndexChanged.connect(self.combo_value)
#define layout
self.resultLayout = QHBoxLayout()
self.resultLayout.addWidget(self.resultLabel)
self.resultLayout.addWidget(self.resultCombo)
self.windowLayout = QVBoxLayout()
self.windowLayout.addLayout(self.resultLayout)
self.windowLayout.addLayout(self.extraCommentLayout)
def combo_value(self):
selected_option = self.resultCombo.currentText()
print str(selected_option)
if selected_option is "passed with additional comments" or "failed":
self.extraCommentLine.setVisible(True)
self.extraCommentLabel.setVisible(True)
elif selected_option is "passed":
self.extraCommentLabel.setVisible(False)
我猜我的def combo_value 丢失了一些东西,但不确定是什么。感谢您的任何提示!
【问题讨论】: