2012-02-16 84 views
1

在我的一個應用程序中,我需要在QTableWidget中有一個QComboBox。QTableWidget中的QComboBox返回NoneType

我寫了這個代碼:

def on_addGoal_clicked(self, checked=False): 
    self.ui.listOfGoals.setRowCount(self.ui.listOfGoals.rowCount() + 1) 

    possible_goals = QtGui.QComboBox() 
    possible_goals.addItems(["greater_than", "maximize", "minimize" \ 
          , "smaller_than", "between"]) 

    self.ui.listOfGoals.setCellWidget(self.ui.listOfGoals.rowCount() - 1, 
             1, possible_goals) 

並正確添加QComboBox。

但是,當我嘗試使用self.ui.listOfGoals.item(r,1)檢索此QComboBox時,返回None。

我還是新來的PyQt,所以我可能錯過了這裏的東西。有什麼建議麼?

回答

1

使用cellWidget方法檢索機設定爲setCellWidget一個小部件:

possible_goals = self.ui.listOfGoals.cellWidget(r, 1) 
+0

完美!這很好。 – Renan 2012-02-17 03:49:37