Resolved. I’m creating a fullscreen app with C++ and Qt. In the screen l have a graphicsScene (and a View for it) that takes out a section of the screen. l can’t figure out how to get the coordinates right.
l want the view size to match the size of the container. l can either create a view that is larger than the container so there are scrollbars (don’t want initially) but the point (0,0) is at the top-left corner (l want this) OR a view that is smaller but the point (0,0) is no longer in the top-left corner, there are ‘margins’. l want the (0,0) point to be top-left so l can programmatically draw a grid.
scene = new NoteMatrix(LayoutB2);
view = new QGraphicsView(scene);
scene->setSceneRect(0,0,view->frameSize().width(), view->frameSize().height());
view->fitInView(view->sceneRect());
view->setAlignment(Qt::AlignLeft);
scene->addRect(0, 0, scene->width(), scene->height()); //visualize boundaries
QWidget *widget = new QWidget(parent);
widget->setLayout(LayoutB2);
mainLayout->setStretchFactor(widget, 1);
setCentralWidget(widget);
I resolved my initial problem. There was nothing wrong with the coordinates. I need to set the alignment to whichever side l wish, in this scenario left.
If you want to fit a scene in QGraphicsview
Use this for setting scene rect..If you set the rect with width and height less than or eaual to of views..No scroll bars will be displayed else it will.
Try also QGraphicsView::fitInView().