2013-08-03 2 views

답변

2

당신은 QtDesigner에서 그것을 할 수 없습니다 당신은 사용자가 선택에 상관없이 이전 값으로 돌아갑니다 함수와 currentIndexChanged 신호 연결해야합니다 :

예 :

import sys 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가 옵션을 표시 할 수 있지만이 옵션 중 하나도 선택할 수 없습니다. selectionMode가 NoSelection으로 설정된 tebleWidget과 마찬가지로. – GiannisIordanou

+0

그래서 combobox를 활성화하려면 사용자가 클릭하여 확장하고 다른 값을 찾으십시오. 그러나 값을 변경하려고하면 이전 값이 설정됩니까? –

+0

정확히. 선택된 배경색을 흰색으로 변경하여 선택한 항목의 파란색을 잃을 수 있으며 comboBox의 색인이 이전 값으로 설정되면 연결합니다. 그러나 선택 항목의 윤곽이 여전히 있습니다. – GiannisIordanou

관련 문제