PDA

View Full Version : When to use QGraphicsScene or QWidget



fossill
9th February 2007, 23:44
I'm a little confused as to WHEN you want to use a QWidget and WHEN you want to use a QGraphicsScene, could somebody elaborate on that or point me to some docs that have already covered it? I'm having a difficult time finding such information.

For instance, take the demo Tetrix, could you use a QGraphicsScene for the "board" area where all tetris blocks are? Or is QGraphicsScene limited to requiring the entire space of the window at all times?

Any help would be appreciated. Thanks!

jacek
9th February 2007, 23:59
I'm a little confused as to WHEN you want to use a QWidget and WHEN you want to use a QGraphicsScene
Actually you always have to use QWidget or one of its subclasses. A special case of a widget is QGraphicsView which is capable of displaying QGraphicsScene and QGraphicsItems that scene contains.


For instance, take the demo Tetrix, could you use a QGraphicsScene for the "board" area where all tetris blocks are?
Yes, you could. You can also subclass QWidget and do all of the drawing yourself, but it will be much easier if you use QGraphicsScene and QGraphicsItems.


Or is QGraphicsScene limited to requiring the entire space of the window at all times?
No, it's not. QGraphicsView behaves just like other widgets, so you can use QWidget::setGeometry() or layouts to place it wherever you want.

wysota
10th February 2007, 00:58
If I were to make a rule of a thumb, I'd say that you should use QGraphicsView whenever you want to create a large amount of objects that either change their state very often (animate) or require interaction with the user (selecting, moving, zooming). In other situations use QWidget.