0

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.

deprecated
  • 57
  • 1
  • 7

1 Answers1

0

If you want to fit a scene in QGraphicsview

view->setScene(YourScene);
view->setSceneRect(0,0,view->frameSize().width(),view->frameSize().height());

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().

ScarCode
  • 3,074
  • 3
  • 19
  • 32
  • This didn't resolve it for me. There is still empty space around the view area. I tried this with both also setting a rect for the scene and only setting it for the view. Thanks for giving me something anyway. – deprecated Jun 06 '12 at 08:21
  • No dice, sorry. Does anyone know a comprehensive article about how the coordinates in this enviroment work? I've read the GraphicScene documents already. Looks like l need to break this down to the atom to figure it out for myself. :( – deprecated Jun 07 '12 at 08:43
  • I tagged your answer as the right one because it helped me resolve my issue and only was missing the setting of alignment. – deprecated Jun 12 '12 at 11:23