2

QGISプラグイン用の適切なGUIを作成するためにpyQT4.8.3を使用しています

フォームには3つのウィジェットがあります

my_comboBox , my_lineEdit , my_spinBox

comboBoxに3つのエントリがあると仮定します

'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

では、コンボボックスから選択した文字列(またはインデックス値)に基づいて、フォーム内のウィジェットの有効な状態を切り替えるにはどうすればよいですか?

適切な信号->スロットの割り当ては何ですか?QbuttonBoxとは異なり、QcomboBoxはSetDisabledスロットを起動しません

ありがとう。

4

1 に答える 1

4

文字列をウィジェットにマップする辞書を作成します。

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応じて配置します。

于 2013-01-26T22:45:53.410 に答える