2013-02-28 29 views
0

我用QT Designer設計了我當前的GUI。底層代碼創建並啓動多個線程。對於每個線程,我都設置了幾個QPushButtons:開始,停止,暫停,恢復和狀態。我想將它們分組,但它們不是唯一的,所以我需要從信號槽中爲每個相關按鈕設置啓用的屬性,具體取決於哪個按鈕已被點擊。我試着爲每組按鈕創建一個QButtonGroup。我可以得到sender(),但沒有看到如何訪問屬於該組的其他按鈕。已經嘗試了幾件事,但沒有運氣。如何訪問插槽內的按鈕組成員?

回答

0

好的,我想我有我需要的。問題在於如何根據發件人的身份設置組中按鈕的啓用狀態?

我有可能被控制的x個線程數。在每個QButtonGroup按鈕的對象名排序如下:

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] 

這個程序將基於所發送的對象名狀態:

# 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 

也許不是最高效的,但它讓我在那裏...