2013-08-03 35 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

相关问题