Results 1 to 2 of 2

Thread: eventFilter: pop-up custom widget

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default eventFilter: pop-up custom widget

    'morning,

    I have a custom QWidget, myWid, that pops up when the user mouses over a QPushButton. The QWidget pops-up adjacent to (slightly overlapping) this pushButton. I want myWid to remain shown (popped up) as long as the mouse is over either the QPushButton *or* myWid. My eventFilter looks like this:

    Qt Code:
    1. bool Window::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if(event->type() == QEvent::Enter)
    4. {
    5. if(obj == myPB)
    6. {
    7. myWid->show();
    8. return QWidget::eventFilter(obj, event);
    9. }
    10. return QWidget::eventFilter(obj, event);
    11.  
    12. else if(event->type() == QEvent::Leave)
    13. {
    14. if(obj == myPB)
    15. {
    16. if(!myWid->underMouse())
    17. {
    18. myWid->hide();
    19. return QWidget::eventFilter(obj, event);
    20. }
    21. return QWidget::eventFilter(obj, event);
    22. }
    23. return QWidget::eventFilter(obj, event);
    24. }
    25. return QWidget::eventFilter(obj, event);
    26. }
    To copy to clipboard, switch view to plain text mode 

    the "hide()" above is conditional: if the mouse is over myWid, do not hide() it when Leave myPB. This doesn't work: the panel flickers on/off rapidly or closes when I mouse over it. I understand why this is happening, but I can't figure out an alternative. Suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: eventFilter: pop-up custom widget

    You can use a timer to hide the popup. This way you'll manage to receive an enter event on the popup before it gets closed. You can then stop the timer so that it doesn't trigger hide(). I think that has a chance to work.

    An alternative would be to react on help event instead - this way your popup would behave exactly as a tooltip.

  3. The following user says thank you to wysota for this useful post:

    vonCZ (22nd November 2007)

Similar Threads

  1. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38
  2. Simple custom widget won't size properly
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 13:12
  3. Custom tab widget question
    By PrimeCP in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 11:17
  4. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00
  5. Replies: 4
    Last Post: 24th March 2006, 22:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.