pyqt4中的组合框中的下拉事件/回调 [英] dropdown event/callback in combo-box in pyqt4

查看:318
本文介绍了pyqt4中的组合框中的下拉事件/回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个回调或事件下拉在pyqt4组合框中?正如 self.connect(self.ui.combobox,SIGNAL(activated(int)),self.refresh

view() property)。
我不知道有任何信号。



但你可以设置一个eventFilter,它将通过使用 installEventFilter ,并实现 eventFilter 方法:

 从PyQt4 import QtCore,QtGui 
class ShowEventFilter(QtCore.QObject):
def eventFilter(self,filteredObj,event):
if event
打印弹出显示
#做任何你想要的操作
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_()


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

解决方案

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_()

这篇关于pyqt4中的组合框中的下拉事件/回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆