PDA

View Full Version : QGraphicsView and Scrolling



validator
1st August 2008, 14:20
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?


#include "mainwindow.h"



#include <QtGui>

MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
{

currentPosition = 0;
populateScene();

scene->addLine(QLineF(-100,0,5000,0),QPen(Qt::green));
view1 = new QGraphicsView(scene);



scrollbar = new QScrollBar(Qt::Horizontal, this);




/*view1->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);*/




QVBoxLayout *vertical = new QVBoxLayout(this);
QWidget *subWidget = new QWidget(this);
QHBoxLayout *layout = new QHBoxLayout(subWidget);
layout->addWidget(view1);

vertical->addWidget(subWidget);
vertical->addWidget(scrollbar);

connect(scrollbar, SIGNAL(sliderMoved(int)), this, SLOT(moveViews(int)));


}

void MainWindow::populateScene()
{
scene = new QGraphicsScene;
}

void MainWindow:: moveViews(int value)
{
int moveBy = value - currentPosition;
view1->scroll(-moveBy, 0);
view2->scroll(-moveBy, 0);

currentPosition = value;
}

jpn
1st August 2008, 20:23
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.

validator
4th August 2008, 07:54
I want to use two GraphicsView , when I set scrollbarvalue , I want to move both of them.
How can I do it.

validator
5th August 2008, 07:03
answer ???

GUIDeveloper
7th September 2017, 22:11
Connect one scrollbar's valueChanged(or similar) signal to another scroll bar's setValue(or similar) slot.

j

d_stranz
8th September 2017, 00:27
I am sure that after 9 years of waiting, the OP is absolutely delighted to see this reply.