Coordinates for QGraphicsView
-
I placed a QGraphicsView inside a tab widget using QTCreator. In QtCreator the dimensions of the graphicsView is 6, 6, 687, 319.
When I try to get the coordinates and size of the view via these commands:int sceneStartCornerX = ui->testGridGraphicsView->x(); //X coordinate of the left to corner of the QGraphicsView (6)
int sceneStartCornerY = ui->testGridGraphicsView->y(); //Y coordinate of the left to corner of the QGraphicsView (6)
int sceneEndCornerX = ui->testGridGraphicsView->width(); //Width of the QGraphicsScene (687)
int sceneEndCornerY = ui->testGridGraphicsView->height(); //height of the QGraphicsScene (319)the returned results are 0, 0, 100, 30
When I try to map the scene to the view and place rectItems, the items are skewed within the scene. Is there something else I need to do to make sure the ui->testGridGraphicsView values match the coordinates in QTCreator?
I know I must be missing something. The view is inside a frame if that makes a difference.
Thanks!
-
Hi,
When are you requesting these values ?
-
Until the widgets are shown they have no "physical" dimensions.
Also note that the size of the scene and the view do not necessarily match unless you made it so.
-
This is what I did when I created the scene.
//create the scene
scene_ = new QGraphicsScene(sceneStartCornerX_,
sceneStartCornerY_,
sceneEndCornerX,
sceneEndCornerY,
ui->testGridGraphicsView);ui->testGridGraphicsView->setScene(scene_); //attach the scene to the view (QGraphicsView)
//smooth graphics ui->testGridGraphicsView->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing); -
Why not just build a "size less" scene ?
-
How are you placing the items on your scene ?
-
Please provide a minimal compilable example that reproduces that issue.