You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Saturday, November 1st 2014, 10:35am

Problem with QGraphicsView and QGraphicsScene

Hi there,

in a MainWindow I have the following code to draw two lines in QGraphicsScene and show them in a QGraphicsView:


Source code

1
2
3
4
5
6
7
8
9
10
11
scene = new QGraphicsScene();
ui->graphicsView->setScene(scene);
ui->graphicsView->scale(1, -1);

QGraphicsLineItem *hLine = new QGraphicsLineItem(0, 0, 100, 0);
QGraphicsLineItem *vLine = new QGraphicsLineItem(0, 0, 0, 100);
scene->addItem(hLine);
scene->addItem(vLine);

scene->setSceneRect(-5, -5, 110, 110);
ui->graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatioByExpanding);


It shows the two lines correctly, but they're verry small!
The Problem is, that I want the lines to be of a size that only a smal space is between the end of the lines an the grahicsView's bord.
Do I have to modify the SceneRect? (I want to have a small frame around the lines; this is why I used (-5, -5, 110, 110), so there should be a frame of 5pt, but i isn't.)

Does anyone has an idea what the problem could be?

Greetings,
Algorithm93