Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.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 如何基于QcomboBox索引切换小部件的启用状态_Python_Pyqt_Pyqt4 - Fatal编程技术网

Python 如何基于QcomboBox索引切换小部件的启用状态

Python 如何基于QcomboBox索引切换小部件的启用状态,python,pyqt,pyqt4,Python,Pyqt,Pyqt4,我使用PyQt4.8.3为QGIS插件创建一个合适的GUI 表单中有三个小部件 my_comboBox , my_lineEdit , my_spinBox 假设comboBox有三个条目 'combo_first_item' , 'combo_second_item' , 'combo_third_item' 我真正想要的是 if 'combo_second_item' is selected, then my_lineEdit toggles state to disabled if '

我使用PyQt4.8.3为QGIS插件创建一个合适的GUI

表单中有三个小部件

my_comboBox , my_lineEdit , my_spinBox
假设comboBox有三个条目

'combo_first_item' , 'combo_second_item' , 'combo_third_item'
我真正想要的是

if 'combo_second_item' is selected, then my_lineEdit toggles state to disabled
if 'combo_third_item' selected, then my_spinBox toggles state to disabled
那么,如何根据combobox中选择的字符串(或索引值)切换表单中小部件的启用状态呢

正确的信号->插槽分配应该是什么? 与QbuttonBox不同,QcomboBox不会触发SetDisabled插槽


谢谢。

制作一个字典,将字符串映射到小部件:

widgets = {'combo_first_item': my_comboBox,
           'combo_second_item': my_lineEdit,
           'combo_third_item': my_spinBox}
和一个插槽:

def disableWidget(currentIndex):
     widget = widgets[currentIndex]
     widget.setEnabled(False)
     # or anything else you want to do on the widget
然后您可以将
currentIndexChanged[QString]
信号连接到此:

comboBox.currentIndexChanged['QString'].connect(disableWidget)
或者,您可以使用
currentIndexChanged[int]
和列表,而不是字典


PS:如果它在类实例中,则相应地放置
self

制作一个字典,将字符串映射到小部件:

widgets = {'combo_first_item': my_comboBox,
           'combo_second_item': my_lineEdit,
           'combo_third_item': my_spinBox}
和一个插槽:

def disableWidget(currentIndex):
     widget = widgets[currentIndex]
     widget.setEnabled(False)
     # or anything else you want to do on the widget
然后您可以将
currentIndexChanged[QString]
信号连接到此:

comboBox.currentIndexChanged['QString'].connect(disableWidget)
或者,您可以使用
currentIndexChanged[int]
和列表,而不是字典

PS:如果它在类实例中,则相应地放置
self