Python 如何基于QcomboBox索引切换小部件的启用状态
我使用PyQt4.8.3为QGIS插件创建一个合适的GUI 表单中有三个小部件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 '
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