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

Dehumanizer
- 284
- 1
- 3
- 14

unice
- 2,655
- 5
- 43
- 78
-
You mean a signal that is emitted when the dropdown menu is shown? I.e., when the user clicks on the combobox? – Ferdinand Beyer Aug 11 '11 at 06:42
-
yes, when the user clicks on the combobox. – unice Aug 11 '11 at 07:47
2 Answers
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

Matej Repinc
- 16
- 2