Results 1 to 8 of 8

Thread: eventFilter: test if enter a subWidget in my subclassed QWidget

  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: test if enter a subWidget in my subclassed QWidget

    I've subclassed QWidget to make a button panel: BuPan. BuPan consists of buttons, a slider, and checkBoxes: it's a small panel that pops up next to a QPushButton in my mainApplication like so:

    Qt Code:
    1. bool Window:eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if(event->type() == QEvent::Enter)
    4. {
    5. if(obj == myQPushButton)
    6. {
    7. myBuPan->move(xloc, yloc);
    8. myBuPan->show();
    9. return QWidget::eventFilter(obj, event)
    10. }
    11. etc...
    12. }
    To copy to clipboard, switch view to plain text mode 


    pb[0] is a button in myBuPan. I want to check for an Enter event on this particular button within BuPan; I thought I could do the following:

    Qt Code:
    1. bool Window:eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if(event->type() == QEvent::Enter)
    4. {
    5. if(obj == myQPushButton)
    6. {
    7. myBuPan->move(xloc, yloc);
    8. myBuPan->show();
    9. return QWidget::eventFilter(obj, event);
    10. }
    11. if(obj == myBuPan->get_pb(0))
    12. {
    13. qDebug("HIT!!");
    14. return QWidget::eventFilter(obj, event);
    15. }
    16. etc...
    17.  
    18. // ...and I have the following in bupan.h:
    19.  
    20. QList<QPushButton *> pb;
    21. QPushButton *get_pb(int value) { return pb[value]; }
    To copy to clipboard, switch view to plain text mode 

    Shouldn't this work? ...er, it's not. ...ideas?

    Or will I have to add an "enterEvent(QEvent *event)" method to the BuPan class itself? If I have to do this second option: How can I write the bupan "enterEvent" method so that it's generic... for example, so that pb[0] and pb[2] will capture enterEvents on one instance of BuPan, but on another instance only pb[4] might capture the events?
    Last edited by vonCZ; 9th December 2007 at 13:25. Reason: typo

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: eventFilter: test if enter a subWidget in my subclassed QWidget

    You can either install the window as event filter for BuPan and the button inside BuPan, and leave your code like it is now, or(better), install BuPan as event filter for the button, and create an eventFilter for BuPan.

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

    Default Re: eventFilter: test if enter a subWidget in my subclassed QWidget

    Quote Originally Posted by marcel View Post
    You can either install the window as event filter for BuPan and the button inside BuPan, and leave your code like it is now,
    thanks Marcel. The reason it wasn't working: I didn't installEventFilter() properly. Working now.

    Quote Originally Posted by marcel View Post
    or(better), install BuPan as event filter for the button, and create an eventFilter for BuPan.
    I'm still not sure how to do it this way. Currently--in my mainApplication eventFilter ("Window")--I include events to filter in by referencing specific widget-objects to test whether the mouse enters/leaves the objects. But I don't know how to create an eventFilter for a subclassed QWidget that would be flexible. For example, some of my BuPan instances will have 10+ buttons, none of which need to be filtered, whereas other BuPans might have 7 buttons, half of which need to be filtered, etc...

  4. #4
    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: test if enter a subWidget in my subclassed QWidget

    I'd suggest intercepting QEvent::ToolTip instead of QEvent::Enter...

  5. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: eventFilter: test if enter a subWidget in my subclassed QWidget

    Quote Originally Posted by wysota View Post
    I'd suggest intercepting QEvent::ToolTip instead of QEvent::Enter...
    Just for curiosity and my better understanding. Can you explain the reason for this ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: eventFilter: test if enter a subWidget in my subclassed QWidget

    Quote Originally Posted by Gopala Krishna View Post
    Just for curiosity and my better understanding. Can you explain the reason for this ?
    So that you can eliminate "accidental" hovering.

  7. The following user says thank you to marcel for this useful post:

    Gopala Krishna (10th December 2007)

  8. #7
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: eventFilter: test if enter a subWidget in my subclassed QWidget

    Quote Originally Posted by marcel View Post
    So that you can eliminate "accidental" hovering.
    Sorry for posting out of topic but one final question. Is this accidental hovering prevented by using timers , while sending Tooltip event ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  9. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: eventFilter: test if enter a subWidget in my subclassed QWidget

    Yes, most likely. On enter a timer is started and on leave the timer is disabled.
    When and if the timer triggers, the tooltip event is posted.

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.