Results 1 to 6 of 6

Thread: QGraphicsView and Scrolling

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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.