Results 1 to 3 of 3

Thread: Scrolling 2 QGraphicsViews with 1 scrollbar

  1. #1
    Join Date
    Mar 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Scrolling 2 QGraphicsViews with 1 scrollbar

    Hi, i have a scrolling issue. I read lots of docs, googled, etc - but couldn't figure it out. The idea is to scroll 2 QGraphicsViews with the scrollbar of one of them. This is what i did:

    Qt Code:
    1. class QPianoRoll : public QWidget {
    2.  
    3. Q_OBJECT
    4.  
    5. public:
    6. QPianoRoll(){
    7.  
    8. currentScrollPosition = 0;
    9.  
    10. QHBoxLayout *layout = new QHBoxLayout;
    11.  
    12. // both, QNoteEditor and QVerticalPiano are derived from QGraphicView
    13.  
    14. piano = new QVerticalPiano();
    15. layout->addWidget(piano);
    16.  
    17. QNoteEditorCore * editor = new QNoteEditorCore();
    18. wrapper = new QNoteEditor(editor);
    19. QScrollBar * scrollbar = wrapper->verticalScrollBar();
    20. connect(scrollbar, SIGNAL(valueChanged(int)),this,SLOT(scrollRoll(int)));
    21.  
    22. layout->addWidget(wrapper,2);
    23. layout->setAlignment(Qt::AlignLeft);
    24. setLayout(layout);
    25.  
    26. }
    27.  
    28. private :
    29. QNoteEditor * wrapper;
    30. QVerticalPiano * piano;
    31. int currentScrollPosition;
    32.  
    33. public slots :
    34. void scrollRoll(int value) {
    35. int relative = currentScrollPosition - value;
    36. piano->scroll(0,relative);
    37. currentScrollPosition = value;
    38. }
    39.  
    40. };
    To copy to clipboard, switch view to plain text mode 

    It's quite the same implementation as introduced here, but unfortunately it doesn't work. The slot scrollRoll just moves the visible scene up and down and does not scroll any contents. What am I doing wrong ?

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scrolling 2 QGraphicsViews with 1 scrollbar

    Hi!

    Untested, but why don't you set the value of the pianos vertical scrollbar directly?
    Qt Code:
    1. connect(wrapper->verticalScrollBar(), SIGNAL(valueChanged(int)),piano->verticalScrollBar(),SLOT(setValue(int)));
    To copy to clipboard, switch view to plain text mode 
    This requires them to have the same ranges though. But if you want to move synchronize their scrolling they should have!

    HIH

    Johannes

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Scrolling 2 QGraphicsViews with 1 scrollbar

    I agree with Joh about connecting the scroll bars directly, but you might also try the following in your slot:
    Qt Code:
    1. piano->viewport()->scroll(0,relative);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Multiple QGraphicsViews with one QGraphicsScene
    By alisami in forum Qt Programming
    Replies: 3
    Last Post: 22nd March 2010, 03:02
  2. scrolling spectrogram
    By mcarter in forum Qwt
    Replies: 2
    Last Post: 30th November 2009, 14:22
  3. Scrolling QTextEdit
    By Dayton in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2009, 21:11
  4. Replies: 3
    Last Post: 2nd February 2009, 23:40
  5. ScrollBar inside QTreeWidget is Blurring on Scrolling
    By santosh.kumar in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2008, 14:33

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.