Qt Graphics View Framework (Qt Developers Meetup Isreal)

  • 545 views
Uploaded on

http://www.meetup.com/QtEverywhere/Tel-Aviv-Yafo-IL/1077772/

http://www.meetup.com/QtEverywhere/Tel-Aviv-Yafo-IL/1077772/

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
545
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
13
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. vitali.pe@gmail.com vitali.p@volicon.com QT Graphics View Framework [vitali]: ~/qt-secene-demos/ >> python cool_intro.py Traceback (most recent call last): File "PySideexamplesopengloverpainting.py", line 198, in paintEvent self.resizeGL(self.width(), self.height()) File "PySideexamplesopengloverpainting.py", line 227, in resizeGL glViewport(((width - side) / 2), ((height - side) / 2), side, side) ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type Traceback (most recent call last): File "PySideexamplesopengloverpainting.py", line 198, in paintEvent self.resizeGL(self.width(), self.height()) File "PySideexamplesopengloverpainting.py", line 227, in resizeGL glViewport(((width - side) / 2), ((height - side) / 2), side, side) ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
  • 2. Soo... QGraphicsScene.. Basically it’s a canvas library on (a lot of) steroids. Features: Model/View Architecture. It’s own event system (not signals & slots) Low level rendering (with QPainter) Input Handling (mouse & keyboard) Simple animation Support for embedding QWidgets Collision detection Drag & Drop ….
  • 3. Demo App https://bitbucket.org/vitalipe/sggle/wiki/Home
  • 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
  • 8. Rendering in Qt 5 QML Qt Webkit QWidget QPainter SceneGraph 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.
  • 13. Questions ?