PDA

View Full Version : How to have fixed size QGraphicsView & QGraphicsScene



mihnen
21st August 2012, 17:22
I'm trying to have a fixed size wysiwyg editor for creating labels. Currently I am trying to implement this with a QGraphicsScene & QGraphicsView populated with QGraphicsTextItem that will take up the whole view.

The problem I am having is how in the world do I get the QGraphicsView to be the same size as the scene, I need this to be a fixed size so that I can use it to do autosizing on the text within it. There are so many different ways I have seen attempted to do this such as using contentsRect(), viewport->setFixedSize(), using setSceneRect(). I also have the border-style set to none and setFrameStyle(QFrame::NoFrame). But alas I just cannot get this to work.

Am doing something wrong or is this the wrong approach. I really don't want to have to implement a complete custom widget to do all this when most of the functionality is built into the QGraphicsTextItem.

StrikeByte
21st August 2012, 19:11
So you want to have a fixed size for the QGraphicsView and the QGraphicsScene ?
Or you want to resize the QGraphicsView and QGraphicsScene to the size of the text?

mihnen
21st August 2012, 20:11
A Fixed size for the QGraphicsView & QGraphicsScene. I basically want to use a view the exact same size as the scene. The fact that there even is a scene is just a fact of the way qt works, I don't care about it, I just want a fixed size widget to add QGraphicTextItems into. The Text will simply be autosized by using the size of the QRect of the view and checking the bounding rect of the font with QFontMetrics.