如何使QComboBox下拉菜单保持打开状态

时间:2014-09-08 22:12:17

标签: python pyqt

我想知道如何让QComboBox下拉菜单保持打开状态。

from PyQt4 import QtCore, QtGui    
app = QtGui.QApplication([])

class Combo(QtGui.QComboBox):
    def __init__(self, *args, **kwargs):
        super(Combo, self).__init__()
        self.addItems(['Item_1','Item_2','Item_3','Item_4','Item_5'])
        self.show()

tree=Combo()
sys.exit(app.exec_())

1 个答案:

答案 0 :(得分:1)

为了使QComboBox的下拉菜单保持打开,请覆盖其内置的hidePopup()方法。

from PyQt4 import QtCore, QtGui    
app = QtGui.QApplication([])

class Combo(QtGui.QComboBox):
    def __init__(self, *args, **kwargs):
        super(Combo, self).__init__()
        self.addItems(['Item_1','Item_2','Item_3','Item_4','Item_5'])
        self.show()

    def hidePopup (self):
        pass

inst=Combo()
sys.exit(app.exec_())
相关问题