Results 1 to 3 of 3

Thread: Why does clicking a QToolButton generate a leaveEvent? Is there a workaround?

  1. #1
    Join Date
    Dec 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Why does clicking a QToolButton generate a leaveEvent? Is there a workaround?

    For some reason, whenever the menu-button part of the QToolButton gets clicked, it generates a momentary leaveEvent (at least when it is in a toolbar). I even tested underMouse() in the leaveEvent, and it returns false. Why is this? Is there a way to fix this?

    Sample for testing:
    Qt Code:
    1. from PyQt4.QtGui import *
    2.  
    3. class MainWindow(QMainWindow):
    4. def __init__(self):
    5. super().__init__()
    6. toolbar = QToolBar(self)
    7. toolbar.addWidget(ToolButton())
    8.  
    9. class ToolButton(QToolButton):
    10. def __init__(self, parent=None):
    11. super().__init__(parent)
    12.  
    13. self.setText('test')
    14. self.setPopupMode(QToolButton.MenuButtonPopup)
    15. self.setMenu(QMenu())
    16. self.menu().addAction('Stub')
    17.  
    18. def enterEvent(self, event):
    19. print('entered')
    20. super().enterEvent(event)
    21.  
    22. def leaveEvent(self, event):
    23. print('left')
    24. super().leaveEvent(event)
    25.  
    26. if __name__ == '__main__':
    27. import sys
    28. application = QApplication(sys.argv)
    29. window = MainWindow()
    30. window.show()
    31. sys.exit(application.exec_())
    To copy to clipboard, switch view to plain text mode 

    I'm using PyQt 4.10.1 Qt4.8.4 x64 with Py3.3.1 x64 with Win7
    Last edited by slobberchopz; 24th December 2013 at 23:16.

  2. #2
    Join Date
    Nov 2011
    Posts
    79
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 5 Times in 5 Posts

    Default Re: Why does clicking a QToolButton generate a leaveEvent? Is there a workaround?

    Right, you click on your button, it brings up the menu window and focus moved from button to menu

  3. #3
    Join Date
    Dec 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why does clicking a QToolButton generate a leaveEvent? Is there a workaround?

    Nope. Because a moment later it switches back to enterEvent(); and anyways, even if focus changed, the mouse didn't. leave/enterEvents reflect mouse position, not focus.

    Well, I've found a way to avoid dealing with leave/enter that suits my needs. For anyone who does care, and who's PyQt version/setup presents such a problem, simply double check with QApplication.widgetAt(QCursor().pos()), that *does* return the correct info.

Similar Threads

  1. mouseMoveEvent and leaveEvent Problems
    By Furkan in forum Qt Programming
    Replies: 9
    Last Post: 29th December 2010, 15:25
  2. QTabBar + leaveEvent + mouseMoveEvent
    By enlightened_j in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2010, 00:13
  3. Workaround for a Qt ui bug
    By eurodatar in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2010, 17:12
  4. QWidget::leaveEvent
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2007, 18:28
  5. enterEvent, leaveEvent, setWindowFlags
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2007, 10:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.