Results 1 to 4 of 4

Thread: QStackerWidget and mouse events

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QStackerWidget and mouse events

    Hi,
    (Qt4 SUSE 10)
    I have a QStackedWidget with several widgets in it, on top of another widget that serves as a dialog.
    But I can't trap the mouse button clicks on the QStackedWidget or the current visible widget in it.
    In order to see the event traffic, I installed an event filter for the QStackedWidget on the dialog widget, and I show there all events that the event filter gets, and in deed, mouse button clickes just don't get trapped in the event filter.
    I turned on mouse tracking, I made sure the QStackedWidget is enabled (same with its children) I even turened on mouse grabbing - the result is always the same.
    I get mouse enter and mouse leave events, and the right mouse button click is trapped as context menu event, wheel events,some move move events when i get on the widget (but this stops after few move events?!) but no mouse buttn press events.
    Can some one tell me what I am I missing here?
    Maybe there is some option I need to turn on/off that I am no aware of?

    Here is some of the relevant code:
    Qt Code:
    1. m_widgetStack = new QStackedWidget(this);
    2. m_tabR = new tabR();
    3. m_tabP = new tabP();
    4. m_tabS = new tabS();
    5. m_tabT = new tabT();
    6. m_widgetStack->setGeometry(m_sMenu->width(),0,this->width()-m_sMenu->width(),this->height());
    7. m_widgetStack->addWidget(m_tabR);
    8. m_widgetStack->addWidget(m_tabP);
    9. m_widgetStack->addWidget(m_tabS);
    10. m_widgetStack->addWidget(m_tabT);
    11.  
    12.  
    13. m_widgetStack->grabMouse();
    14. m_widgetStack->setEnabled(true);
    15. m_widgetStack->setMouseTracking(true);
    16. m_widgetStack->setFocusPolicy( Qt::StrongFocus);
    17. m_widgetStack->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. bool MainDlg::eventFilter(QObject *obj,QEvent *event)
    2. {
    3. qDebug("MainDlg::eventFilter %d",event->type());
    4. switch(event->type())
    5. {
    6. case QEvent::MouseButtonPress :qDebug("keyPress");
    7. return true;
    8. break;
    9. case QEvent::MouseButtonRelease: qDebug("keyRelease");
    10. return true;
    11. break;
    12. default: return false;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    I thought maybe I need to work with the child widgets of the QStackedWidget, so I insatalled the event filter on the first child widget (the first which is visible) and the result is the same...

    Any pointers (such as "did you make sure that...") or help will be very appretiated.
    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStackerWidget and mouse events

    Where did you try to click?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QStackerWidget and mouse events

    Mouse events go directly to the child widget under the cursor and the parent widget does not receive the event if child widget handles it. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it.

    I think you might need to install event filter more deeper level (to an invidual "bottom level" widgets, eg. widgets inside the widgets in the stack.. how horrible sentence is that) in order to receive all possible mouse events.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QStackerWidget and mouse events

    Thanks for the replys, I found the problem...
    I had on each widget in the stacked widget a goupbox that grouped all the controls, and the group box was getting all the mouse vents, but I was not quering the events of the group box (I just forgot I had that group box)...

    Thanks.

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.