Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将QChekBox状态连接到QCOMBOX状态?_Python_Pyqt_Signals Slots_Qcombobox_Qcheckbox - Fatal编程技术网

Python 如何将QChekBox状态连接到QCOMBOX状态?

Python 如何将QChekBox状态连接到QCOMBOX状态?,python,pyqt,signals-slots,qcombobox,qcheckbox,Python,Pyqt,Signals Slots,Qcombobox,Qcheckbox,我想启用一个组合框-这是从Qt Designer的属性编辑器中禁用的-但是,仅当用户选中该复选框时。我写了以下内容,但它不起作用。它被放在我的main类的\uuuu init\uuu方法中。你能帮我弄明白为什么吗 if self.dlg.checkBox.isChecked(): self.dlg.cmbvectorLayer6.setEnabled(True) 编辑: 我现在在我的主类的\uuuuu init\uuuu方法中有以下内容: self.dlg.checkBox.state

我想启用一个组合框-这是从Qt Designer的属性编辑器中禁用的-但是,仅当用户选中该复选框时。我写了以下内容,但它不起作用。它被放在我的main类的
\uuuu init\uuu
方法中。你能帮我弄明白为什么吗

if self.dlg.checkBox.isChecked():
    self.dlg.cmbvectorLayer6.setEnabled(True)
编辑

我现在在我的主类的
\uuuuu init\uuuu
方法中有以下内容:

self.dlg.checkBox.stateChanged[int].connect(self.enablecombo)
启用组合的
enablecombo
为:

def enablecombo(self):
    self.dlg.cmbvectorLayer6.setEnabled(True)
它可以很好地激活组合框。但是我不知道如何在复选框被取消选中时禁用组合框

self.dlg.checkBox.stateChanged[int].connect(self.checkcombo) 
当前状态是什么,只需调用一个函数进行检查,然后根据其输出启用/禁用它

def checkcombo():
    if self.dlg.checkBox.isChecked():
        self.dlg.cmbvectorLayer6.setEnabled(True)
    else:
        self.dlg.cmbvectorLayer6.setEnabled(False)

您正在检查状态是否已选中,但需要检查isEnabled

QCheckBox
类继承了
QAbstractButton
,因此您可以使用该信号执行您想要的操作:

    self.dlg.checkBox.toggled.connect(self.enablecombo)
    ...

def enablecombo(self, checked):
    self.dlg.cmbvectorLayer6.setEnabled(checked)
或直接连接到组合框:

    self.dlg.checkBox.toggled.connect(self.dlg.cmbvectorLayer6.setEnabled)

(您也可以在Qt Designer中使用设置这些类型的直接连接)

也许我写得不好。。combobox被禁用,而不是复选框。。但是,如果用户想首先使用combobox,则需要选中复选框,以便启用combobox。对不起,我误解了这个问题。你犯了什么错误?根据你的代码,它应该能正常工作,我也理解。。只是在def checkcombo()中需要传递自参数,复选框应始终处于启用状态。。选中时,禁用的组合框应变为启用
    self.dlg.checkBox.toggled.connect(self.dlg.cmbvectorLayer6.setEnabled)