2

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

Dehumanizer
  • 284
  • 1
  • 3
  • 14
unice
  • 2,655
  • 5
  • 43
  • 78

2 Answers2

2

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_()
Jeannot
  • 1,165
  • 7
  • 18
0

Maybe you could try

customContextMenuRequested(const QPoint &pos) 

signal (inherited from QWidget)?

agf
  • 171,228
  • 44
  • 289
  • 238