Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5 import QtCore, QtGui, QtWidgets
- # When a QPushButton widget is clicked, its menu (if set) is displayed as a
- # modal popup. However, a Leave event is not being send to the button. From the
- # button point of view, the mouse pointer is, and will always be, inside the
- # widget.
- #
- # In this simple example, logging has added some to monitor what events are
- # being sent to the button when the menu is displayed.
- def typeToStr(eventType):
- for attr in dir(QtCore.QEvent):
- if getattr(QtCore.QEvent, attr) == eventType:
- return attr
- return "Unknown ( " + str(eventType) + ")"
- class PushButton(QtWidgets.QPushButton):
- def event(self, event):
- print(typeToStr(event.type()), event)
- return super(PushButton, self).event(event)
- class Widget(QtWidgets.QWidget):
- def __init__(self, parent=None):
- super(Widget, self).__init__(parent)
- menu = QtWidgets.QMenu()
- for i in range(3):
- menu.addAction("Action " + str(i + 1))
- button = PushButton("Button with menu", self)
- button.setFlat(True)
- button.setMenu(menu)
- button.setGeometry(20, 20, 200, 40)
- app = QtWidgets.QApplication(sys.argv)
- emptyTab = Widget()
- emptyTab.setGeometry(1300, 600, 300, 100)
- emptyTab.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement