Results 1 to 8 of 8

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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.