Results 1 to 5 of 5

Thread: QGraphicsView and QTreeView synchronous scrolling

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Posts
    72
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QGraphicsView and QTreeView synchronous scrolling

    Hi,

    I have coded a GUI where there are QGraphicsView and QTreeView placed, loaded, activated and used.

    There is a need to move QGraphicsScene, that is “assigned” ( set ) to the QGraphicsView downward and upward ( a.k.a to scroll vertically and horizontally ) using set scroll bars ( scroll bar policy set to both widgets as ScrollBarAlwaysOn ) synchronously with QTreeView, so that when one of the widgets is scrolled on some number of pixels, to scroll the second as well.

    The widgets scrolling connected using next code:

    Qt Code:
    1. connect(ui->treeView,SIGNAL(scrolled(int,int)),this,SLOT(scroll_gv(int,int)));
    2.  
    3. connect(ui->graphicsView,SIGNAL(scrolled(int,int)),this,SLOT(scroll_tv(int,int)));
    4.  
    5.  
    6.  
    7. ...
    8.  
    9.  
    10.  
    11.  
    12.  
    13. void MainWindow::scroll_gv(int dx,int dy)
    14.  
    15. {
    16.  
    17. ui->graphicsView->scroll(dx,dy);
    18.  
    19. }
    20.  
    21.  
    22.  
    23. void MainWindow::scroll_tv(int dx,int dy)
    24.  
    25. {
    26.  
    27. ui->treeView->scroll(dx,dy);
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 

    where the scroll is added to custom classes inherited from QGraphicsView and QTreeView and virtual function reimplemented:

    Qt Code:
    1. void QCTreeView::scrollContentsBy ( int dx, int dy )
    2.  
    3. {
    4.  
    5. emit scrolled(dx,dy);
    6.  
    7. }
    8.  
    9.  
    10.  
    11. void qcgraphicsview::scrollContentsBy ( int dx, int dy )
    12.  
    13. {
    14.  
    15. emit scrolled(dx,dy);
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    The problem to correct is next, when I scroll one of the widgets, the second is scrolled as well, but somehow not accurate – all the area of the widget is scrolled and not a widgets internals,

    The scrolling behavior is recorded in next video clip:

    https://www.box.com/s/lpaon61oly45fffyu3kn

    Will you hint why such problem, what properties of the widgets to set, how to code correctly in order the synchronous scroll will work ?

    Thanks in advance for your help.

  2. The following user says thank you to freely for this useful post:


Similar Threads

  1. QGraphicsView and Scrolling
    By validator in forum Qt Programming
    Replies: 5
    Last Post: 8th September 2017, 00:27
  2. QTreeView problem scrolling to end.
    By seneca in forum Qt Programming
    Replies: 7
    Last Post: 22nd December 2015, 12:08
  3. Replies: 3
    Last Post: 25th May 2010, 10:29
  4. Custom scrolling of QGraphicsView
    By hb in forum Qt Programming
    Replies: 0
    Last Post: 12th August 2008, 10:10
  5. QGraphicsView scrolling problem with 4.3.0
    By hb in forum Qt Programming
    Replies: 8
    Last Post: 30th August 2007, 22:18

Tags for this Thread

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.