我有2个QLineEdit-le_A
和le_B
仅摄取数字值,而QCheckBox-chk_box
。
我在le_A
是“控制者”的情况下,当le_B
被选中时,在使chk_box
和chk_box
具有相同的输入时遇到问题(请参阅下面的方案2)。示例方案:
le_A
和le_B
输入任何值。例如le_A
中的值为10,而le_B
中的值为20。
le_A
和le_B
中输入的任何值都将相同。例如如果我在le_A
中输入10,则le_B
将为10。le_B
中的输入相同,le_A
的值将相同。
class CustomTest(QtGui.QWidget):
def __init__(self, parent=None):
super(CustomTest, self).__init__(parent)
# Only numeric values
self.le_A = QtGui.QLineEdit()
self.le_B = QtGui.QLineEdit()
self.chk_box = QtGui.QCheckBox()
lyt = QtGui.QHBoxLayout()
lyt.addWidget(self.le_A)
lyt.addWidget(self.le_B)
lyt.addWidget(self.chk_box)
self.setLayout(lyt)
self.set_connections()
def set_connections(self):
self.chk_box.stateChanged.connect(self.chk_toggle)
def chk_toggle(self):
chk_value = self.chk_box.isChecked()
a_val = self.le_A.text()
b_val = self.le_B.text()
# Inputs in either le_A and le_B should be the same
if chk_value:
# If the values are different, always use a_val as the base value
if a_val != b_val:
self.le_B.setText(str(b_val))
else:
# Inputs in either le_A and le_B can be different
# Currently this is working
pass
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
w = CustomTest()
w.show()
sys.exit(app.exec_())
我有2个QLineEdit-le_A和le_B仅摄取数字值,而QCheckBox-chk_box。每当...
我假设选中此复选框时,您要同步行编辑的内容,然后使其与用户类型相同。如果是这样,则将进行以下更改: