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.
Asked
Active
Viewed 418 times
1 Answers
0
OK, I think I have what I need on this. The problem was how to I set the enabled states of buttons in a group based on the identity of the sender?
I have a possible x number of threads that can be controlled. The objectNames of the buttons in each QButtonGroup are as follows:
pushButton_start_x
pushButton_stop_x
pushButton_status_x
pushButton_pause_x
pushButton_resume_x
In my Python code I have the following dictionary:
# 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]
This routine sets the states based on the objectName of the sender:
# 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
Maybe not the most efficient, but it gets me there...

user2117830
- 41
- 5