4. Architecture Overview
Only 3 Basic components item(s), that are added to the scene,
and one or more views to display the
scene.
View
View
Graphics Scene
Item
Item
VIew
Item
This is the actual QWidget, that is added to
your layout...
Item
Item
5. First, lets talk about rendering widgets in QT
●
●
●
Widget render themselves by overriding paintEvent()
QT uses the “painter's algorithm”
Any Widget can be hardware accelerated.
paintEvent()
1
paintEvent()
2
3
paintEvent()
4
paintEvent()
6. Ok… so what about graphics scene?
The graphics scene, has a different more flexible
and optimized API for drawing and transforms , but
the same principle apply….
1
2
Also up until QT 5 , QML widgets where
implemented on top of QGraphicsView
3
4
7. Rendering in Qt 4.8
QML
Via QGraphicsView
Qt Webkit
QWidget
QPainter
OpenGL
Renderer
Software
Renderer
9. Why? you ask...
Well… because painter’s algorithm will fuckup any
OpenGL based rendering pipeline!
QML
Z-Buffering FTW!
SceneGraph
Yes you can get away with it on desktops when
you're not developing AAA games… but Qt Quick
is for moblie remember ?
OpenGL
Renderer
10. The Item, View & Scene
QGraphicsScene:
●
●
●
●
itemAt(x : float, y : float)
addItem(item : QGraphicsItem)
addPixmap( pixmap : QPixmap)
selectedItems()
...
Providing an interface for managing items
Propagating events to each item
Managing item state, such as selection and focus handling
Providing (untransformed) rendering functionality.
11. The Item, View & Scene
QGraphicsItem:
●
●
●
●
●
●
setPos(pos : QPointF)
setTransform(t : QTransform)
setEnabled( enabled : bool)
childItems()
...
Mouse and keyboard input events
Drag and drop
Parent-child relationships.
Collision detection.
Has many many built-in sub types
If you want to implement layers effects, etc… you need a custom item
12. The Item, View & Scene
QGraphicsView:
●
●
●
●
●
mapFromScene(pos : QPointF)
mapToScene(pos : QPointF)
centerOn(pos : QPointF)
setTransform(t : QTransform)
...
Visualizes the contents of a scene.
Is a subclass of QWidget
A scene can have multiple views attached to it.
Translates keyboard and mouse events to scene events
Has it’s own transform matrix.