2013-08-03 57 views

回答

2

你不能做到這一點在QtDesigner你必須連接currentIndexChanged信號與功能將恢復無論用戶選擇舊值:

示例:

導入系統 來自PyQt4導入QtGui,QtCore

class MainWidget(QtGui.QWidget): 
    def __init__(self): 
     super(MainWidget, self).__init__() 
     # Create a combo and set the second item to be selected 
     self.combo = QtGui.QComboBox() 
     self.combo.addItems(['foo', 'bar', 'baz']) 
     self.combo.setCurrentIndex(1) 
     # Connect the combo currentIndexChanged signal 
     self.combo.activated.connect(self.on_combo_change) 
     # Setup layout 
     self.layout = QtGui.QVBoxLayout() 
     self.layout.addWidget(self.combo) 
     self.setLayout(self.layout) 

    def on_combo_change(self, index): 
     # Whatever the user do, just ignore it and revert to 
     # the old value. 
     self.combo.setCurrentIndex(1) 


app = QtGui.QApplication(sys.argv) 
mw = MainWidget() 
mw.show() 
app.exec_() 
+0

這不是我的目標。我的目標是comboBox能夠顯示它的選項,但是這些選項都不能被選中。像一個tebleWidget,其selectionMode設置爲NoSelection。 – GiannisIordanou

+0

所以你想要組合框被啓用,用戶可以點擊,展開它,尋找其他值,但是如果他試圖改變值,舊值將被設置? –

+0

確切地說,我可以將選擇背景顏色更改爲白色,以便丟失所選項目的藍色,並且如果組合框的索引更改爲設置舊值,則連接。但仍然存在選擇的輪廓。 – GiannisIordanou

相關問題