Results 1 to 10 of 10

Thread: QEvent for QGraphicsView scrollbars?

Threaded View

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

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.