SlideShare une entreprise Scribd logo
1  sur  29
Qt Advanced
Part I




1
Contents
• Graphics View
• Qt Property System
• Animation Framework




2
Qt Advanced
Graphics View




3
Graphics View In General
• Provides a surface for managing and interacting with a large number of custom-
  made 2D graphical items
• Event propagation architecture provided
    • Allows precise double-precision interaction capabilities for the items on the scene
    • Items can handle key, mouse press, move, release and double click events
    • Tracks mouse movement
• Uses Binary Space Partitioning tree to provide very fast item discovery
• Items may be QWidgets, although not very usual




4
Coordinate Systems
• Three coordinate systems, corresponding to the graphics view classes (parts of
  the
  th system):
         t )
    • Graphics Item
    • Graphics Scene
    • Graphics View
• Convenience functions for coordinate mappings are provided




5
Graphics Item – QGraphicsItem
• Graphical item on the screen
• Several standard it
  S         l t d d item classes exist: rectangle, ellipse, t t
                            l        i t    t   l   lli     text
• Items live in their own local coordinate system.
• Coordinates are usually centered around its center point (0, 0), and this is also the center
  for all transformations.
• Item features
    • Mouse press, move, release, double click, mouse hover event, wheel event, context menu
      events
    • Keyboard input focus, key events
    • Drag and drop
    • Grouping
    • Collision detection
         • Set a shape for your items
         • Override collision detection function if needed




6
Graphics Scene – QGraphicsScene
• Container for item objects
    • P id a f t interface for managing a large number of it
      Provides fast i t f     f          i   l     b    f items
    • Propagates events to each item
    • Manages item state (
           g             (selection, focus))

    QGraphicsScene scene;
    QGraphicsItem *rect = scene addRect(QRectF(0 0 100 100));
                          scene.addRect(QRectF(0, 0, 100,
    scene.addItem(newGraphicsItem);

    QGraphicsItem *item = scene.itemAt(50, 50);
    // item == rect




7
Graphics View - QGraphicsView
• The view widget for displaying the contents of a QGraphicsScene
• You can add a QGraphicsView directly from the UI Designer
    • Like an empty canvas for your Graphics Items
• C
  Convenient and efficient use of t
        i t d ffi i t           f transformations
                                       f    ti
    • Uses QMatrix or QTransform
        • rotate()
                ()
        • scale()
        • translate()
        • shear()




8
Transformations

    • View can transform scene’s co ordinate system
                          scene s co-ordinate
    • Easy to add transformations to graphic view items or to the whole view

             QTransform transform;
             transform.translate(50, 50);
             transform.rotate(45);
             transform.scale(0.5, 1.0);
             transform scale(0 5 1 0);
             view.setTransform(transform);

             // Also available:
             view.rotate(45);




9
Adding QWidgets to Graphics View
• QGraphicsWidget
     • Concrete base class of all widget items in the graphics scene
     • Layout management
     • Geometry management
• Inherited by QGraphicsProxyWidget
     • Used for adding normal QWidgets to the scene


     QGraphicsScene scene;
     QLineEdit *edit = new QLineEdit;
     QGraphicsProxyWidget *proxy = scene.addWidget(edit);
     edit->isVisible(); // returns true
     QGraphicsView view(&scene);
     view.show();




10
Graphics View Classes




11
Items are not Widgets

     • Th major diff
       The     j difference b t
                            between QG hi It
                                     QGraphicsItem and, say QLabel i th t th
                                                     d      QL b l is that the
       former is not a QWidget subclass
     • This has, among others, the following implications:
         • You can’t place QWidgets in a QGraphicsScene (without the proxy class
           described earlier)
         • You can’t place QGraphicsItems outside a QGraphicsScene
         • You can’t use Qlayout-derived layout managers with QGraphicsItems –
           QGraphicsLayout is the base class for layouts instead
         • QGraphicsScene/QGraphicsItem has its own internal event system that is slightly
                 p                 p                                y                g y
           different from the regular QEvent system
         • QGraphicsItems can, unlike QWidgets, be arbitrarily transformed
              • This allows the creation of items that support high q
                                                         pp      g quality zooming etc
                                                                         y       g




12
Existing Graphics Items
• QGraphicsLineItem – A line segment
• QAbstractGraphicsShapeItem – Common baseclass for “shape items”, ie. ellipses,
  polygons etc.
• QGraphicsEllipseItem – An ellipse or ”pie segment”
                                              g
• QGraphicsPolygonItem – A polygon
• QGraphicsRectItem – A rectangle
• QGraphicsPathItem – A QPainterPath
• QGraphicsPixmapItem – A pixmap
• QGraphicsTextItem – A rich text string (can be editable)
• QGraphicsSimpleTextItem – A non-editable plain text string
• QGraphicsSvgItem – An SVG element




13
Event Handling
• Event handling for QGraphicsItems is very similar to QWidget
• Example handlers:
     •   keyPressEvent(QKeyEvent*)
     •   mouseMoveEvent(QGraphicsSceneMouseEvent*)
                         (Q   p                     )
     •   contextMenuEvent(QGraphicsSceneContextMenuEvent*)
     •   dragEnterEvent(QGraphicsSceneDragDropEvent*)
     •   focusInEvent(QFocusEvent*)
         f    I E   t(QF    E    t*)
     •   hoverEnterEvent(QGraphicsSceneHoverEvent*)
• And similar to QWidget::event(QEvent*) there is
                     g         (       )
  QGraphicsItem::sceneEvent(QEvent*) that receives all events for an item




14
Qt Advanced
Qt Property System




15
Qt Property System – 1/2
     • Data members of QObject-derived classes can be exposed as properties
     • Properties are defined in class declarations using the Q PROPERTY macro
                                                              Q_PROPERTY
     • Syntax:
          Q_PROPERTY( type name READ getFunction
          [WRITE setFunction ] [RESET resetFunction ]
          [DESIGNABLE bool ] [SCRIPTABLE bool ] [STORED bool ] )
     • Examples:
          Q_PROPERTY( QString title READ title WRITE setTitle )
          Q_PROPERTY( bool enabled READ isEnabled WRITE setEnabled )


     • Properties can be accessed using the functions QObject::property() and
       QObject::setProperty()
          • No need to even know the exact type of the object you are manipulating!
          • If the property named in QObject::setProperty() does not exist, it will be dynamically added to the
            object at run-time
                      run time
     • Many widget members are Qt properties
          • Used e.g. in the animation framework




16
Qt Property System – 2/2

     // MyObject.h
     class MyObject : public QObject {
      Q_OBJECT
      Q_PROPERTY(QString text READ text WRITE setText)
     public:         // Constructor and destructor omitted for simplicity
      void setText(const QString& text) const { m_text = text; }
      QString text() const { return m_text; }
     p
     private:
      QString m_text;
     };


     // Usage in SomeCode.cpp:
     MyObject* myObject = new MyObject();
     QObject* object = myObject;


     myObject->setText(”Some text”);              // Access either in the normal way...
     object->setProperty(”text”, ”Other text”); // ... or by using the property system




17
Qt Advanced
Animation Framework




18
Introduction 1(2)

     • I Qt 4.6 a new Animation F
       In   46        A i ti Framework was introduced
                                     k     i t d    d
     • The idea is to provide an easy and scalable way of creating animated
       and smooth GUIs
         • Hides the complexity of handling timers
         • Provides a set of pre-defined easing curves, custom curves can be
           provided b the d
               id d by h developer as needed
                                l            d d
     • Works by modifying the properties of the QObjects being animated




19
Introduction 2(2)
• Easy to use together with the State Machine Framework to provide animated
  transitions b t
  t    iti    between states
                       t t
     • State Machine Framework is introduced in the next session
• Normally the animations have a finite duration
     • QTimeLine used as a timer behind the scenes
     • Can be made to loop and run backwards
• If duration is set to -1, the animation will run until explicitly stopped




20
Main Classes




21
Example – Animating a Button
• What do you think the example below does?


     Q
     QPushButton button("Animated Button");
                       (                 )
     button.show();


     QPropertyAnimation animation(&button, "geometry");
     animation.setDuration(10000);
     animation.setStartValue(QRect(0, 0, 100, 30));
     animation.setKeyValueAt(0.5, QRect(250, 250, 100, 30));
     animation.setEndValue(QRect(0, 0, 100, 30));
     animation.start();




22
QGraphicsObject

     • All normal QWidgets can easily be animated as they are, since they
                                    y                   y               y
       derive from QObject
         • This is not the case with QGraphicsItems
         • Because QObject-functionality is not always needed; this way this common
                     QObject functionality
           base class remains lighter weight
     • A new class was introduced to help with custom graphics classes:
       QGraphicsObject
         • Provides access to signals, slots and properties
         • Use it as your base class when needed




23
Non-QObject Graphics Classes 1(2)

     • H
       How t use the existing non-QObject graphics classes with th
           to     th   i ti       QObj t      hi    l       ith the
       Animation FW?
         • QGraphicsPixmapItem, QGraphicsLineItem
         • QAbstractGraphicsShapeItem-derived classes
     • Derive from the wanted utility class, and
         • Add QObject as another base class when needed
         • In other words, do exactly like QGraphicsObject does it!




                                                   Add when needed




24
Non-QObject Graphics Classes 2(2)

     • Th custom subclass (
       The     t    b l     (MyPixmapItem) can now also expose it b
                                 i           )      l          its base
       class’s member variables as properties
         • A suitable setter function is needed in the base class
     • For example, base class provides a setter and a getter function and
       subclass uses these to declare a property:

         class MyPixmapItem : public QObject, public QGraphicsPixmapItem {
          Q_OBJECT
          // Refers to QGraphicsItem::pos() and setPos()
          Q_PROPERTY(QPointF pos READ pos WRITE setPos)
            ...




25
Animation Groups 1(2)

     • Classes QSequentialAnimationGroup and
       QParalleAnimationGroup can be used to run multiple animations
       in sequence or in parallel
     • Their base class QAnimationGroup further derives from
                        Q             p
       QAbstractAnimation
        • An animation group can be used wherever a ”normal” animation could –
          e.g. a g p within a g p
            g group            group
        • Enables building very complex animation sequences




26
Animation Groups 2(2)

     QPropertyAnimation* animation1 = new QPropertyAnimation(...);
     QPropertyAnimation* animation2 = new QPropertyAnimation(...);
     QPropertyAnimation* animation3 = new QPropertyAnimation(...);
     QPropertyAnimation* animation4 = new QPropertyAnimation(...);


     QParallelAnimationGroup *parallel = new QParallelAnimationGroup();
     parallel->addAnimation(animation2);
     parallel->addAnimation(animation3);


     QSequentialAnimationGroup* seq = new QSequentialAnimationGroup();
     seq->addAnimation(animation1);
           dd i    i ( i     i 1)
     seq->addAnimation(parallel);
     seq->addAnimation(animation4);


     seq->start();




27
Easing Curves

     • Th Animation FW provides multiple pre-made easing curves f your
       The A i ti          id     lti l        d     i          for
       convenience
         • Represented by the class QEasingCurve
         • Custom curves can implemented by the developer; see the class
           documentation for details
     • Typically used to control e.g. how the animation starts and/or finishes
        yp     y                   g
         • QEasingCurve::OutBounce
         • QEasingCurve::InOutQuad
         •…
         QPropertyAnimation animation(&button, "geometry");
         animation.setEasingCurve(QEasingCurve::OutBounce);
                           g            g

     • Take a look at the Easing Curves example in the Qt Demo tool



28
Summary
• Graphics View is the framework used for nice graphics and animations in Qt
     • Think of it as a canvas that contains graphical items
     • Items can move around freely
     • Enables creation of attractive GUIs
• Qt extends basic C++ functionality with its property system
     • An extremely versatile mechanism for exposing object’s internals
                  y                           p    g j
         • Breaks a basic OO-principle: information encapsulation
     • Works via the meta-object system
     • U d e.g. b th A i ti F
       Used     by the Animation Framework
                                         k
• The new Animation Framework makes implementing complex animations even
  easier than before
     • No need to worry about timers
     • Nice extra features provided, e.g. easing curves


29

Contenu connexe

Tendances

Special Effects with Qt Graphics View
Special Effects with Qt Graphics ViewSpecial Effects with Qt Graphics View
Special Effects with Qt Graphics Viewaccount inactive
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Frameworkaccount inactive
 
Practical Model View Programming
Practical Model View ProgrammingPractical Model View Programming
Practical Model View ProgrammingMarius Bugge Monsen
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentICS
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2NokiaAppForum
 
Copy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with QtCopy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with Qtaccount inactive
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? ICS
 
Qt on Real Time Operating Systems
Qt on Real Time Operating SystemsQt on Real Time Operating Systems
Qt on Real Time Operating Systemsaccount inactive
 
Meet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIMeet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIICS
 
Using Multi-Touch and Gestures with Qt
Using Multi-Touch and Gestures with QtUsing Multi-Touch and Gestures with Qt
Using Multi-Touch and Gestures with Qtaccount inactive
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickICS
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
Introducing the New Prefab Workflow - Unite LA
Introducing the New Prefab Workflow - Unite LAIntroducing the New Prefab Workflow - Unite LA
Introducing the New Prefab Workflow - Unite LAUnity Technologies
 
Animation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIsAnimation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIsaccount inactive
 
A Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkA Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkZachary Blair
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtICS
 
Technical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemTechnical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemUnity Technologies
 

Tendances (19)

Special Effects with Qt Graphics View
Special Effects with Qt Graphics ViewSpecial Effects with Qt Graphics View
Special Effects with Qt Graphics View
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Framework
 
Practical Model View Programming
Practical Model View ProgrammingPractical Model View Programming
Practical Model View Programming
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
 
Copy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with QtCopy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with Qt
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
Qt on Real Time Operating Systems
Qt on Real Time Operating SystemsQt on Real Time Operating Systems
Qt on Real Time Operating Systems
 
Meet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIMeet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UI
 
Using Multi-Touch and Gestures with Qt
Using Multi-Touch and Gestures with QtUsing Multi-Touch and Gestures with Qt
Using Multi-Touch and Gestures with Qt
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
Cross Platform Qt
Cross Platform QtCross Platform Qt
Cross Platform Qt
 
Introducing the New Prefab Workflow - Unite LA
Introducing the New Prefab Workflow - Unite LAIntroducing the New Prefab Workflow - Unite LA
Introducing the New Prefab Workflow - Unite LA
 
Animation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIsAnimation Framework: A Step Towards Modern UIs
Animation Framework: A Step Towards Modern UIs
 
A Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkA Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application Framework
 
State Machine Framework
State Machine FrameworkState Machine Framework
State Machine Framework
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
 
Technical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemTechnical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab System
 

Similaire à Petri Niemi Qt Advanced Part 1

Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio
 
Petri Niemi Qt Web Kit
Petri Niemi Qt Web KitPetri Niemi Qt Web Kit
Petri Niemi Qt Web KitNokiaAppForum
 
Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IICS
 
KDE 4.1 Plasma widgets
KDE 4.1 Plasma widgetsKDE 4.1 Plasma widgets
KDE 4.1 Plasma widgetsMarco Martin
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIICS
 
03 - Qt UI Development
03 - Qt UI Development03 - Qt UI Development
03 - Qt UI DevelopmentAndreas Jakl
 
Qt Itemviews, The Next Generation
Qt Itemviews, The Next GenerationQt Itemviews, The Next Generation
Qt Itemviews, The Next GenerationMarius Bugge Monsen
 
The Ring programming language version 1.10 book - Part 104 of 212
The Ring programming language version 1.10 book - Part 104 of 212The Ring programming language version 1.10 book - Part 104 of 212
The Ring programming language version 1.10 book - Part 104 of 212Mahmoud Samir Fayed
 
Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4ICS
 
The Ring programming language version 1.6 book - Part 178 of 189
The Ring programming language version 1.6 book - Part 178 of 189The Ring programming language version 1.6 book - Part 178 of 189
The Ring programming language version 1.6 book - Part 178 of 189Mahmoud Samir Fayed
 
Qt Itemviews, The Next Generation (Bossa09)
Qt Itemviews, The Next Generation (Bossa09)Qt Itemviews, The Next Generation (Bossa09)
Qt Itemviews, The Next Generation (Bossa09)Marius Bugge Monsen
 
The Ring programming language version 1.4 book - Part 28 of 30
The Ring programming language version 1.4 book - Part 28 of 30The Ring programming language version 1.4 book - Part 28 of 30
The Ring programming language version 1.4 book - Part 28 of 30Mahmoud Samir Fayed
 
Qt & Webkit
Qt & WebkitQt & Webkit
Qt & WebkitQT-day
 
The Ring programming language version 1.9 book - Part 111 of 210
The Ring programming language version 1.9 book - Part 111 of 210The Ring programming language version 1.9 book - Part 111 of 210
The Ring programming language version 1.9 book - Part 111 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 101 of 196
The Ring programming language version 1.7 book - Part 101 of 196The Ring programming language version 1.7 book - Part 101 of 196
The Ring programming language version 1.7 book - Part 101 of 196Mahmoud Samir Fayed
 

Similaire à Petri Niemi Qt Advanced Part 1 (20)

Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick components
 
Petri Niemi Qt Web Kit
Petri Niemi Qt Web KitPetri Niemi Qt Web Kit
Petri Niemi Qt Web Kit
 
Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part I
 
KDE 4.1 Plasma widgets
KDE 4.1 Plasma widgetsKDE 4.1 Plasma widgets
KDE 4.1 Plasma widgets
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
 
03 - Qt UI Development
03 - Qt UI Development03 - Qt UI Development
03 - Qt UI Development
 
Qt Itemviews, The Next Generation
Qt Itemviews, The Next GenerationQt Itemviews, The Next Generation
Qt Itemviews, The Next Generation
 
The Ring programming language version 1.10 book - Part 104 of 212
The Ring programming language version 1.10 book - Part 104 of 212The Ring programming language version 1.10 book - Part 104 of 212
The Ring programming language version 1.10 book - Part 104 of 212
 
Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4
 
Qt Application Programming with C++ - Part 1
Qt Application Programming with C++ - Part 1Qt Application Programming with C++ - Part 1
Qt Application Programming with C++ - Part 1
 
Qt programming-using-cpp
Qt programming-using-cppQt programming-using-cpp
Qt programming-using-cpp
 
The Ring programming language version 1.6 book - Part 178 of 189
The Ring programming language version 1.6 book - Part 178 of 189The Ring programming language version 1.6 book - Part 178 of 189
The Ring programming language version 1.6 book - Part 178 of 189
 
Qt Itemviews, The Next Generation (Bossa09)
Qt Itemviews, The Next Generation (Bossa09)Qt Itemviews, The Next Generation (Bossa09)
Qt Itemviews, The Next Generation (Bossa09)
 
Core animation
Core animationCore animation
Core animation
 
Qt Widgets In Depth
Qt Widgets In DepthQt Widgets In Depth
Qt Widgets In Depth
 
The Ring programming language version 1.4 book - Part 28 of 30
The Ring programming language version 1.4 book - Part 28 of 30The Ring programming language version 1.4 book - Part 28 of 30
The Ring programming language version 1.4 book - Part 28 of 30
 
Qt & Webkit
Qt & WebkitQt & Webkit
Qt & Webkit
 
The Future of Qt Widgets
The Future of Qt WidgetsThe Future of Qt Widgets
The Future of Qt Widgets
 
The Ring programming language version 1.9 book - Part 111 of 210
The Ring programming language version 1.9 book - Part 111 of 210The Ring programming language version 1.9 book - Part 111 of 210
The Ring programming language version 1.9 book - Part 111 of 210
 
The Ring programming language version 1.7 book - Part 101 of 196
The Ring programming language version 1.7 book - Part 101 of 196The Ring programming language version 1.7 book - Part 101 of 196
The Ring programming language version 1.7 book - Part 101 of 196
 

Plus de NokiaAppForum

Toshl.com - Od ideje do končnega izdelka
Toshl.com - Od ideje do končnega izdelka Toshl.com - Od ideje do končnega izdelka
Toshl.com - Od ideje do končnega izdelka NokiaAppForum
 
Alexander Oswald The Future of Maemo and Symbian
Alexander Oswald The Future of Maemo and SymbianAlexander Oswald The Future of Maemo and Symbian
Alexander Oswald The Future of Maemo and SymbianNokiaAppForum
 
Dominik Gusenbauer Qt Mobility
Dominik Gusenbauer  Qt MobilityDominik Gusenbauer  Qt Mobility
Dominik Gusenbauer Qt MobilityNokiaAppForum
 
Andreas Jakl, Qt Symbian Maemo Quickstart
Andreas Jakl, Qt Symbian Maemo QuickstartAndreas Jakl, Qt Symbian Maemo Quickstart
Andreas Jakl, Qt Symbian Maemo QuickstartNokiaAppForum
 
Mobile Web Development from Scratch
Mobile Web Development from ScratchMobile Web Development from Scratch
Mobile Web Development from ScratchNokiaAppForum
 
Wolfgang Damm Wikitude
Wolfgang Damm WikitudeWolfgang Damm Wikitude
Wolfgang Damm WikitudeNokiaAppForum
 
Miha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web RuntimeMiha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web RuntimeNokiaAppForum
 
Jure Sustersic Monetization through Ovi Services
Jure Sustersic Monetization through Ovi ServicesJure Sustersic Monetization through Ovi Services
Jure Sustersic Monetization through Ovi ServicesNokiaAppForum
 
Andreas Jakl Software Development on Nokia Deviceswith Qt
Andreas Jakl Software Development on Nokia Deviceswith QtAndreas Jakl Software Development on Nokia Deviceswith Qt
Andreas Jakl Software Development on Nokia Deviceswith QtNokiaAppForum
 

Plus de NokiaAppForum (11)

Toshl.com - Od ideje do končnega izdelka
Toshl.com - Od ideje do končnega izdelka Toshl.com - Od ideje do končnega izdelka
Toshl.com - Od ideje do končnega izdelka
 
Razum
RazumRazum
Razum
 
Hello Mobile
Hello MobileHello Mobile
Hello Mobile
 
Alexander Oswald The Future of Maemo and Symbian
Alexander Oswald The Future of Maemo and SymbianAlexander Oswald The Future of Maemo and Symbian
Alexander Oswald The Future of Maemo and Symbian
 
Dominik Gusenbauer Qt Mobility
Dominik Gusenbauer  Qt MobilityDominik Gusenbauer  Qt Mobility
Dominik Gusenbauer Qt Mobility
 
Andreas Jakl, Qt Symbian Maemo Quickstart
Andreas Jakl, Qt Symbian Maemo QuickstartAndreas Jakl, Qt Symbian Maemo Quickstart
Andreas Jakl, Qt Symbian Maemo Quickstart
 
Mobile Web Development from Scratch
Mobile Web Development from ScratchMobile Web Development from Scratch
Mobile Web Development from Scratch
 
Wolfgang Damm Wikitude
Wolfgang Damm WikitudeWolfgang Damm Wikitude
Wolfgang Damm Wikitude
 
Miha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web RuntimeMiha Lesjak Mobilizing The Web with Web Runtime
Miha Lesjak Mobilizing The Web with Web Runtime
 
Jure Sustersic Monetization through Ovi Services
Jure Sustersic Monetization through Ovi ServicesJure Sustersic Monetization through Ovi Services
Jure Sustersic Monetization through Ovi Services
 
Andreas Jakl Software Development on Nokia Deviceswith Qt
Andreas Jakl Software Development on Nokia Deviceswith QtAndreas Jakl Software Development on Nokia Deviceswith Qt
Andreas Jakl Software Development on Nokia Deviceswith Qt
 

Dernier

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Petri Niemi Qt Advanced Part 1

  • 2. Contents • Graphics View • Qt Property System • Animation Framework 2
  • 4. Graphics View In General • Provides a surface for managing and interacting with a large number of custom- made 2D graphical items • Event propagation architecture provided • Allows precise double-precision interaction capabilities for the items on the scene • Items can handle key, mouse press, move, release and double click events • Tracks mouse movement • Uses Binary Space Partitioning tree to provide very fast item discovery • Items may be QWidgets, although not very usual 4
  • 5. Coordinate Systems • Three coordinate systems, corresponding to the graphics view classes (parts of the th system): t ) • Graphics Item • Graphics Scene • Graphics View • Convenience functions for coordinate mappings are provided 5
  • 6. Graphics Item – QGraphicsItem • Graphical item on the screen • Several standard it S l t d d item classes exist: rectangle, ellipse, t t l i t t l lli text • Items live in their own local coordinate system. • Coordinates are usually centered around its center point (0, 0), and this is also the center for all transformations. • Item features • Mouse press, move, release, double click, mouse hover event, wheel event, context menu events • Keyboard input focus, key events • Drag and drop • Grouping • Collision detection • Set a shape for your items • Override collision detection function if needed 6
  • 7. Graphics Scene – QGraphicsScene • Container for item objects • P id a f t interface for managing a large number of it Provides fast i t f f i l b f items • Propagates events to each item • Manages item state ( g (selection, focus)) QGraphicsScene scene; QGraphicsItem *rect = scene addRect(QRectF(0 0 100 100)); scene.addRect(QRectF(0, 0, 100, scene.addItem(newGraphicsItem); QGraphicsItem *item = scene.itemAt(50, 50); // item == rect 7
  • 8. Graphics View - QGraphicsView • The view widget for displaying the contents of a QGraphicsScene • You can add a QGraphicsView directly from the UI Designer • Like an empty canvas for your Graphics Items • C Convenient and efficient use of t i t d ffi i t f transformations f ti • Uses QMatrix or QTransform • rotate() () • scale() • translate() • shear() 8
  • 9. Transformations • View can transform scene’s co ordinate system scene s co-ordinate • Easy to add transformations to graphic view items or to the whole view QTransform transform; transform.translate(50, 50); transform.rotate(45); transform.scale(0.5, 1.0); transform scale(0 5 1 0); view.setTransform(transform); // Also available: view.rotate(45); 9
  • 10. Adding QWidgets to Graphics View • QGraphicsWidget • Concrete base class of all widget items in the graphics scene • Layout management • Geometry management • Inherited by QGraphicsProxyWidget • Used for adding normal QWidgets to the scene QGraphicsScene scene; QLineEdit *edit = new QLineEdit; QGraphicsProxyWidget *proxy = scene.addWidget(edit); edit->isVisible(); // returns true QGraphicsView view(&scene); view.show(); 10
  • 12. Items are not Widgets • Th major diff The j difference b t between QG hi It QGraphicsItem and, say QLabel i th t th d QL b l is that the former is not a QWidget subclass • This has, among others, the following implications: • You can’t place QWidgets in a QGraphicsScene (without the proxy class described earlier) • You can’t place QGraphicsItems outside a QGraphicsScene • You can’t use Qlayout-derived layout managers with QGraphicsItems – QGraphicsLayout is the base class for layouts instead • QGraphicsScene/QGraphicsItem has its own internal event system that is slightly p p y g y different from the regular QEvent system • QGraphicsItems can, unlike QWidgets, be arbitrarily transformed • This allows the creation of items that support high q pp g quality zooming etc y g 12
  • 13. Existing Graphics Items • QGraphicsLineItem – A line segment • QAbstractGraphicsShapeItem – Common baseclass for “shape items”, ie. ellipses, polygons etc. • QGraphicsEllipseItem – An ellipse or ”pie segment” g • QGraphicsPolygonItem – A polygon • QGraphicsRectItem – A rectangle • QGraphicsPathItem – A QPainterPath • QGraphicsPixmapItem – A pixmap • QGraphicsTextItem – A rich text string (can be editable) • QGraphicsSimpleTextItem – A non-editable plain text string • QGraphicsSvgItem – An SVG element 13
  • 14. Event Handling • Event handling for QGraphicsItems is very similar to QWidget • Example handlers: • keyPressEvent(QKeyEvent*) • mouseMoveEvent(QGraphicsSceneMouseEvent*) (Q p ) • contextMenuEvent(QGraphicsSceneContextMenuEvent*) • dragEnterEvent(QGraphicsSceneDragDropEvent*) • focusInEvent(QFocusEvent*) f I E t(QF E t*) • hoverEnterEvent(QGraphicsSceneHoverEvent*) • And similar to QWidget::event(QEvent*) there is g ( ) QGraphicsItem::sceneEvent(QEvent*) that receives all events for an item 14
  • 16. Qt Property System – 1/2 • Data members of QObject-derived classes can be exposed as properties • Properties are defined in class declarations using the Q PROPERTY macro Q_PROPERTY • Syntax: Q_PROPERTY( type name READ getFunction [WRITE setFunction ] [RESET resetFunction ] [DESIGNABLE bool ] [SCRIPTABLE bool ] [STORED bool ] ) • Examples: Q_PROPERTY( QString title READ title WRITE setTitle ) Q_PROPERTY( bool enabled READ isEnabled WRITE setEnabled ) • Properties can be accessed using the functions QObject::property() and QObject::setProperty() • No need to even know the exact type of the object you are manipulating! • If the property named in QObject::setProperty() does not exist, it will be dynamically added to the object at run-time run time • Many widget members are Qt properties • Used e.g. in the animation framework 16
  • 17. Qt Property System – 2/2 // MyObject.h class MyObject : public QObject { Q_OBJECT Q_PROPERTY(QString text READ text WRITE setText) public: // Constructor and destructor omitted for simplicity void setText(const QString& text) const { m_text = text; } QString text() const { return m_text; } p private: QString m_text; }; // Usage in SomeCode.cpp: MyObject* myObject = new MyObject(); QObject* object = myObject; myObject->setText(”Some text”); // Access either in the normal way... object->setProperty(”text”, ”Other text”); // ... or by using the property system 17
  • 19. Introduction 1(2) • I Qt 4.6 a new Animation F In 46 A i ti Framework was introduced k i t d d • The idea is to provide an easy and scalable way of creating animated and smooth GUIs • Hides the complexity of handling timers • Provides a set of pre-defined easing curves, custom curves can be provided b the d id d by h developer as needed l d d • Works by modifying the properties of the QObjects being animated 19
  • 20. Introduction 2(2) • Easy to use together with the State Machine Framework to provide animated transitions b t t iti between states t t • State Machine Framework is introduced in the next session • Normally the animations have a finite duration • QTimeLine used as a timer behind the scenes • Can be made to loop and run backwards • If duration is set to -1, the animation will run until explicitly stopped 20
  • 22. Example – Animating a Button • What do you think the example below does? Q QPushButton button("Animated Button"); ( ) button.show(); QPropertyAnimation animation(&button, "geometry"); animation.setDuration(10000); animation.setStartValue(QRect(0, 0, 100, 30)); animation.setKeyValueAt(0.5, QRect(250, 250, 100, 30)); animation.setEndValue(QRect(0, 0, 100, 30)); animation.start(); 22
  • 23. QGraphicsObject • All normal QWidgets can easily be animated as they are, since they y y y derive from QObject • This is not the case with QGraphicsItems • Because QObject-functionality is not always needed; this way this common QObject functionality base class remains lighter weight • A new class was introduced to help with custom graphics classes: QGraphicsObject • Provides access to signals, slots and properties • Use it as your base class when needed 23
  • 24. Non-QObject Graphics Classes 1(2) • H How t use the existing non-QObject graphics classes with th to th i ti QObj t hi l ith the Animation FW? • QGraphicsPixmapItem, QGraphicsLineItem • QAbstractGraphicsShapeItem-derived classes • Derive from the wanted utility class, and • Add QObject as another base class when needed • In other words, do exactly like QGraphicsObject does it! Add when needed 24
  • 25. Non-QObject Graphics Classes 2(2) • Th custom subclass ( The t b l (MyPixmapItem) can now also expose it b i ) l its base class’s member variables as properties • A suitable setter function is needed in the base class • For example, base class provides a setter and a getter function and subclass uses these to declare a property: class MyPixmapItem : public QObject, public QGraphicsPixmapItem { Q_OBJECT // Refers to QGraphicsItem::pos() and setPos() Q_PROPERTY(QPointF pos READ pos WRITE setPos) ... 25
  • 26. Animation Groups 1(2) • Classes QSequentialAnimationGroup and QParalleAnimationGroup can be used to run multiple animations in sequence or in parallel • Their base class QAnimationGroup further derives from Q p QAbstractAnimation • An animation group can be used wherever a ”normal” animation could – e.g. a g p within a g p g group group • Enables building very complex animation sequences 26
  • 27. Animation Groups 2(2) QPropertyAnimation* animation1 = new QPropertyAnimation(...); QPropertyAnimation* animation2 = new QPropertyAnimation(...); QPropertyAnimation* animation3 = new QPropertyAnimation(...); QPropertyAnimation* animation4 = new QPropertyAnimation(...); QParallelAnimationGroup *parallel = new QParallelAnimationGroup(); parallel->addAnimation(animation2); parallel->addAnimation(animation3); QSequentialAnimationGroup* seq = new QSequentialAnimationGroup(); seq->addAnimation(animation1); dd i i ( i i 1) seq->addAnimation(parallel); seq->addAnimation(animation4); seq->start(); 27
  • 28. Easing Curves • Th Animation FW provides multiple pre-made easing curves f your The A i ti id lti l d i for convenience • Represented by the class QEasingCurve • Custom curves can implemented by the developer; see the class documentation for details • Typically used to control e.g. how the animation starts and/or finishes yp y g • QEasingCurve::OutBounce • QEasingCurve::InOutQuad •… QPropertyAnimation animation(&button, "geometry"); animation.setEasingCurve(QEasingCurve::OutBounce); g g • Take a look at the Easing Curves example in the Qt Demo tool 28
  • 29. Summary • Graphics View is the framework used for nice graphics and animations in Qt • Think of it as a canvas that contains graphical items • Items can move around freely • Enables creation of attractive GUIs • Qt extends basic C++ functionality with its property system • An extremely versatile mechanism for exposing object’s internals y p g j • Breaks a basic OO-principle: information encapsulation • Works via the meta-object system • U d e.g. b th A i ti F Used by the Animation Framework k • The new Animation Framework makes implementing complex animations even easier than before • No need to worry about timers • Nice extra features provided, e.g. easing curves 29