问题
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