Scale Scene wrong in second time.
-
Hi to all:
First of all thanks a lot for helping me in this post.
In my application,I create a QgraphicsScene adding lines when a user pushs a button. When the whole scene is created then the application scales the scene to the QGraphicsView. First time it works fine but when the user pushs the button again to add another lines, the scaling does not work fine... the QGraphicsView appears in blank... what I am doing wrong?
This is the part of my code that i do this:
for (int i=0;i<num_lines;i++) { ............................................ line = scene->addLine((lines_struct[i].x_start),(lines_struct[i].y_start),(lines_struct[i].x_end),(lines_struct[i].y_end), black); //Cration of the scene .......................................... } ui->graphicsView->scale(ui->graphicsView->width()/scene->width(),ui->graphicsView->height()/scene->height()); // Adjust map to the graphicsView using a scale
It seems that the ui->graphicsView->scale does the scale in the original scene and not in the update scene...
But I am not sure...
Could anybody help me??Thanks a lot.
-
hi
Second time u press "Add Lines" button, you say
"the QGraphicsView appears in blank."How can that be ?
the lines from first time should be there.Unless u maybe create a new scene ?
You should only call scene = new QGraphicsScene()
ONCE.Whatever is wrong, is NOT shown in that code listed here :)
-
@mrjj Hello, thanks again for helping me.
Yes, it appears in blank. The items are there but they do not appear because it does not scale fine.
I have just one scene and I do "scene=new QGraphicsScene() " in the class constructor so just call once...I do not know what happens... When I add one line in the scene it scale fine, but when I do again the scale, scene appears in blank but I suppose that the items are there..
-
@AlvaroS
Hi
It sounds really odd.
Maybe you can try the
http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html
(its available directly in Creator)With your AddLine code. It has zoom so easy to see if its just a zoom issues in your code or something else.