Results 1 to 10 of 10

Thread: QEvent for QGraphicsView scrollbars?

  1. #1
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QEvent for QGraphicsView scrollbars?

    Is there a way to determine whether or not a mousepress release occurred on a scrollbar? It seems that QEvent::MouseButtonRelease only gets activated when the user releases focus within the graphics view, and not on the scrollbars...

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QEvent for QGraphicsView scrollbars?

    The graphics view inhert the abstract scroll area - that is where the scroll bars enter the picture and that is where you have to look for the events/signals that you are looking for.

  3. #3
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QEvent for QGraphicsView scrollbars?

    Ok, I meant to also tell you that you can get the actual QScrollBar widgets using the verticalScrollbar and horizontalScrollbar methods.

  4. #4
    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: QEvent for QGraphicsView scrollbars?

    J-P Nurmi

  5. #5
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QEvent for QGraphicsView scrollbars?

    Thanks for the tip guys. Is it possible to install an eventfilter on it so that I can access it similar to this:

    Qt Code:
    1. bool theFormName::eventFilter(QObject *o, QEvent *e){
    2. if (o == ui.graphicsView)
    3. if (e->type() == QAbstractSlider::sliderReleased())
    4. // do something
    5. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    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: QEvent for QGraphicsView scrollbars?

    Those are signals so you would use them in the usual way:
    Qt Code:
    1. connect(horizontalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(doSomething()));
    2. connect(horizontalScrollBar(), SIGNAL(sliderReleased()), this, SLOT(doSomething()));
    3. // and so on...
    To copy to clipboard, switch view to plain text mode 

    If you want to use the event filtering approach instead, the corresponding types are QEvent::MouseButtonPress and QEvent::MouseButtonRelease.
    J-P Nurmi

  7. #7
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QEvent for QGraphicsView scrollbars?

    Thanks to both of you, your answers were right on target (as usual).

    I was using an event filter for other portions of my code, and wanted to keep it consistent. But the solution you showed was simple enough...and I'm definitely better off using that rather then complicating the situation.

  8. #8
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QEvent for QGraphicsView scrollbars?

    For the record, then. If you reimplement the scrollContentsBy() function of QAbstractScrollArea, you will receive the delta values from both scroll bars at once, without having to declare slots or install event filters.

    Qt Code:
    1. void MyCustomView::scrollContentsBy(int dx, int dy)
    2. {
    3. // dx = horizontal delta
    4. // dy = vertical delta
    5. }
    To copy to clipboard, switch view to plain text mode 

    Btw, installing an event filter:

    Qt Code:
    1. MyCustomView::MyCustomView(QGraphicsScene *scene, QObject *parent)
    2. : QGraphicsView(scene, parent)
    3. {
    4. horizontalScrollBar()->installEventFilter(this);
    5. verticalScrollBar()->installEventFilter(this);
    6. }
    7.  
    8. bool MyCustomView::eventFilter(QObject *watched, QEvent *event)
    9. {
    10. bool vbar = (object == verticalScrollBar();
    11. bool hbar = (object == horizontalScrollBar();
    12. if (!vbar && !hbar)
    13. return false;
    14.  
    15. switch (event) {
    16. case MouseButtonPress:
    17. if (vbar) { /* someone pressed the vertical bar */ }
    18. else { /* someone pressed the horizontal bar */ }
    19. break;
    20. case MouseButtonPress:
    21. if (vbar) { /* someone released the vertical bar */ }
    22. else { /* someone released the horizontal bar */ }
    23. break;
    24. case MouseMove:
    25. if (vbar) { /* someone pressed and moved the vertical bar */ }
    26. else { /* someone pressed and moved the vertical bar */ }
    27. break;
    28. ...
    29. default:
    30. break;
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 21st November 2006 at 00:45. Reason: changed [quote] to [code]
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  9. #9
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QEvent for QGraphicsView scrollbars?

    thanks for the eventfilter example. I noticed that the SliderReleased() signal only emits a signal for the scrollbar, not the "scroll arrow" buttons. By the name of the function, I guess that makes sense. I was wondering if there was something similar that I can call for the scroll arrow buttons. I've been digging through the QAbstractScrollArea reference, but I'm not sure if that's where I should be looking.

  10. #10
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QEvent for QGraphicsView scrollbars?

    No, I'd go for the event filter in this case.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

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.