Results 1 to 6 of 6

Thread: QGraphicsView and Scrolling

  1. #1
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsView and Scrolling

    Hi. I add line with 5000 pixel into QGraphicsView then I scroll horizontallly but I can not come end of that line . I write my own scrollBar. Code is below

    What is my problem . Do you know?

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3.  
    4.  
    5. #include <QtGui>
    6.  
    7. MainWindow::MainWindow(QWidget *parent)
    8. : QWidget(parent)
    9. {
    10.  
    11. currentPosition = 0;
    12. populateScene();
    13.  
    14. scene->addLine(QLineF(-100,0,5000,0),QPen(Qt::green));
    15. view1 = new QGraphicsView(scene);
    16.  
    17.  
    18.  
    19. scrollbar = new QScrollBar(Qt::Horizontal, this);
    20.  
    21.  
    22.  
    23.  
    24. /*view1->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);*/
    25.  
    26.  
    27.  
    28.  
    29. QVBoxLayout *vertical = new QVBoxLayout(this);
    30. QWidget *subWidget = new QWidget(this);
    31. QHBoxLayout *layout = new QHBoxLayout(subWidget);
    32. layout->addWidget(view1);
    33.  
    34. vertical->addWidget(subWidget);
    35. vertical->addWidget(scrollbar);
    36.  
    37. connect(scrollbar, SIGNAL(sliderMoved(int)), this, SLOT(moveViews(int)));
    38.  
    39.  
    40. }
    41.  
    42. void MainWindow::populateScene()
    43. {
    44. scene = new QGraphicsScene;
    45. }
    46.  
    47. void MainWindow:: moveViews(int value)
    48. {
    49. int moveBy = value - currentPosition;
    50. view1->scroll(-moveBy, 0);
    51. view2->scroll(-moveBy, 0);
    52.  
    53. currentPosition = value;
    54. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 1st August 2008 at 20:14. Reason: missing [code] tags

  2. #2
    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: QGraphicsView and Scrolling

    Why don't you use the built-in scrollbar of QGraphicsView? The default range of QScrollBar is 0-99. Most likely it doesn't match too well with your view.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView and Scrolling

    I want to use two GraphicsView , when I set scrollbarvalue , I want to move both of them.
    How can I do it.

  4. #4
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView and Scrolling

    answer ???

  5. #5
    Join Date
    Aug 2017
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView and Scrolling

    Connect one scrollbar's valueChanged(or similar) signal to another scroll bar's setValue(or similar) slot.

    j

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsView and Scrolling

    I am sure that after 9 years of waiting, the OP is absolutely delighted to see this reply.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 26th February 2009, 10:12
  2. QGraphicsView doesn't repaint itself - Help!
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2008, 14:08
  3. QGraphicsView scrolling problem with 4.3.0
    By hb in forum Qt Programming
    Replies: 8
    Last Post: 30th August 2007, 22:18
  4. Replies: 4
    Last Post: 25th April 2007, 16:54
  5. Replies: 3
    Last Post: 20th February 2007, 13:02

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.