dropdown event/callback in combo-box in pyqt4

£可爱£侵袭症+ 提交于 2019-12-24 01:54:49

问题


is there a callback or event for dropdown in pyqt4 combo box? Just like self.connect(self.ui.combobox,SIGNAL("activated(int)"),self.refresh


回答1:


The QCombobox uses a QAbstractItemView (QListView by default) to display the dropdown items (accessible via the view() property). I am not aware of any signal for that purpose.

But you can set an eventFilter that will do the trick by using installEventFilter on the view of the combobox and implement the eventFilter method:

from PyQt4 import QtCore, QtGui
class ShowEventFilter(QtCore.QObject):
    def eventFilter(self, filteredObj, event):
        if event.type() == QtCore.QEvent.Show:
            print "Popup Showed !"
            # do whatever you want
        return QtCore.QObject.eventFilter(self, filteredObj, event)

if __name__ == '__main__':
    app = QtGui.QApplication([])
    cb = QtGui.QComboBox()
    cb.addItems(['a', 'b', 'c'])

    eventFilter = ShowEventFilter()
    cb.view().installEventFilter(eventFilter)
    cb.show()
    app.exec_()



回答2:


Maybe you could try

customContextMenuRequested(const QPoint &pos) 

signal (inherited from QWidget)?



来源:https://stackoverflow.com/questions/7021768/dropdown-event-callback-in-combo-box-in-pyqt4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!