【问题标题】:dropdown event/callback in combo-box in pyqt4pyqt4中组合框中的下拉事件/回调
【发布时间】:2011-08-11 06:33:59
【问题描述】:

pyqt4 组合框中的下拉菜单是否有回调或事件?就像self.connect(self.ui.combobox,SIGNAL("activated(int)"),self.refresh

【问题讨论】:

  • 您的意思是显示下拉菜单时发出的信号?即,当用户点击组合框时?
  • 是的,当用户点击组合框时。

标签: python combobox pyqt4


【解决方案1】:

QCombobox 使用 QAbstractItemView(默认为 QListView)来显示下拉项目(可通过 view() 属性访问)。 我不知道有任何用于此目的的信号。

但是您可以通过在组合框的视图上使用installEventFilter 并实现eventFilter 方法来设置一个事件过滤器来解决问题:

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】:

    也许你可以试试

    customContextMenuRequested(const QPoint &pos) 
    

    信号(继承自 QWidget)?

    【讨论】:

    • 也许不是答案
    猜你喜欢
    • 2015-06-30
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    • 2021-12-06
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    相关资源
    最近更新 更多