Results 1 to 10 of 10

Thread: QEvent for QGraphicsView scrollbars?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    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; 20th November 2006 at 23:45. Reason: changed [quote] to [code]
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  3. #3
    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.

  4. #4
    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.