0

I have designed my current GUI with QT Designer. The underlying code creates and starts multiple threads. For each thread I have a set up several QPushButtons: Start, Stop, Pause, Resume, and Status. I'd like to group them, but they are not exclusive, so I need to set the enabled attribute from the signaled slot, for each related button, depending on which button has been clicked. I've tried creating a QButtonGroup for each set of buttons. I can get the sender(), but don't see how to get access to the other buttons which belong to the group. Have tried several things, but having no luck.

4

1 に答える 1

0

OK、私はこれに必要なものを持っていると思います。問題は、送信者のIDに基づいてグループ内のボタンの有効な状態をどのように設定するかでした。

制御できるスレッドの数はx個あります。各QButtonGroupのボタンのobjectNamesは次のとおりです。

pushButton_start_x
pushButton_stop_x
pushButton_status_x
pushButton_pause_x
pushButton_resume_x

私のPythonコードには、次の辞書があります。

# Each key represents a button type that requires setting the group's
# buttons enabled state

# Each key's values map to these buttons: [start,stop,status,pause,resume]

testManagerButtonEnableStates = {}
testManagerButtonEnableStates["start"] = [False,True,True,True,False]
testManagerButtonEnableStates["stop"] = [True,False,True,False,False]
testManagerButtonEnableStates["pause"] = [False,False,True,False,True]
testManagerButtonEnableStates["resume"] = [False,True,True,True,False]

このルーチンは、送信者のobjectNameに基づいて状態を設定します。

# Note that the status button does not require any action here

def setButtonGroupEnabledStates(self):
    buttonType = str(self.sender().objectName().toAscii()).split('_')[1]
    if buttonType == "status":
        return
    i = 0
    for button in self.sender().group().buttons():
        button.setEnabled(self.testManagerButtonEnableStates[buttonType][i])
        i+=1

おそらく最も効率的ではありませんが、それは私をそこに導きます...

于 2013-02-28T21:53:59.883 に答える