SlideShare a Scribd company logo
Qt – External Interaction and Graphics



Andreas Jakl
Senior Technical Consultant
Forum Nokia

                                     20 September, 2010
                                                 v3.0.0
Contents
  – Events
  – Low Level Painting
  – Graphics View Framework
  – Optimizing Images
Events
Events
• UI applications are event-based
    – Wait for user to interact
    – Then start working on the requested task
• Alternative
    – Polling for status changes
      “Is the user pressing a button?”
→ Events save processing time, thus battery life

                                                   Picture credits: Pearson Scott Foresman
                                                                             Public domain
Events vs. Signals?
•   Signals
     – For using widgets
     – e.g., push button should
       return clicked() signal, not
       low-level mouse or key events
•   Events
     – For implementing widgets
             •   Modifying existing widgets
             •   New widgets
     – e.g., implement own push button: handle mouse and key events and emit clicked()
       signal when necessary
Events and Signals
• Mouse button’s way to become a clicked() signal
                               QCoreApplication::exec()
    Mouse button   Operating
                                 QEventLoop::exec()
      released      system

                                               QEvent sent through event dispatcher
                                QPushButton::event()
                                                                           QAbstractButton::
                               QAbstractButton::event()
                                                                         mouseReleasedEvent()
                                  QWidget::event()
                                                                         → emit clicked() signal
                                  QObject::event()
                                                                      Signal & slots connection

                                                                    Custom slot that handles button
                                                                                  click
Event Loop
• Threads in Qt can have an event loop
   – Initial thread starts its loop through QCoreApplication::exec()
   – Other threads: QThread::exec()
• Events
   – Derived from QEvent
   – Source:
       •   Window system (QMouseEvent, QKeyEvent)
       •   Generated by Qt itself (QTimerEvent)

   – Handled by QObject subclass (especially widgets)
QEvent
• Get type of event through QEvent::type()
    – 100+ events defined through enum values in Qt
    – Own events can be defined
• Event is an instance of a QEvent subclass
    – Adds additional information about event
    – e.g., QMouseEvent: buttons, position, ...
Handling Events in Widgets
       – Events delivered to event() function of QObject
       – Calls appropriate virtual event handler functions
qwidget.cpp
 bool QWidget::event(QEvent *event)
 {
     Q_D(QWidget);
     // ...
     switch (event->type()) {
     case QEvent::MouseMove:
         mouseMoveEvent((QMouseEvent*)event);
         break;                                 You only need to
     case QEvent::Paint:
         paintEvent((QPaintEvent*)event);       override virtual, pre-
                                                defined handler method
         break;
     case QEvent::Close:
         closeEvent((QCloseEvent*)event);
         break;                                 from QWidget base class
         // ...
     default:
         return QObject::event(event);
     }
     return true;
 }
Example: Ticker
• Scrolling text
    – 1 Pixel / 30 ms
    – Demonstrates Timer events
• Handles 4 events
    – Paint event: manual drawing of the text
    – Timer event: regular call-backs
    – Show event: start timer when widget is shown
    – Hide event: end timer when widget becomes invisible
Ticker – General Definition
ticker.h                                                ticker.cpp
 #ifndef TICKER_H                                        #include "ticker.h"
 #define TICKER_H
                                                         Ticker::Ticker(QWidget* parent)
 #include <QtGui>                                                : QWidget(parent)
                                                         {
 class Ticker : public QWidget                               m_offset = 0;
 {                                                           m_timerId = 0;
     Q_OBJECT                                            }
     Q_PROPERTY(QString text READ text WRITE setText)
                                                         void Ticker::setText(const QString &newText)
 public:                                                 {
     Ticker(QWidget* parent = 0);                            m_text = newText;
     void setText(const QString &newText);                   update();
     QString text() const { return m_text; }                 updateGeometry();
     QSize sizeHint() const;                             }

 protected:                                              // Return recommended size of this widget
     void paintEvent(QPaintEvent* event);                QSize Ticker::sizeHint() const
     void timerEvent(QTimerEvent* event);                {
     void showEvent(QShowEvent* event);                      // Determine size required by the text
     void hideEvent(QHideEvent* event);                      // First argument isn't needed here -> 0
                                                             return fontMetrics().size(0, text());
 private:                                                }
     QString m_text;
     int m_offset;
     int m_timerId;
 };

 #endif // TICKER_H
Ticker – Event Handling
ticker.cpp                                                 ticker.cpp
 void Ticker::paintEvent(QPaintEvent* /*event*/)            void Ticker::timerEvent(QTimerEvent* event)
 {                                                          {
     QPainter painter(this);                                    // Called by the system at intervals
                                                                if (event->timerId() == m_timerId)
       // Get required width of the text                        {
       int textWidth = fontMetrics().width(text());                 // Increase offset by 1 to simulate movement
       if (textWidth < 1)                                           ++m_offset;
           return;                                                  if (m_offset >= fontMetrics().width(text()))
                                                                         m_offset = 0;
       // Draw the text as many times as necessary                  // Call to QWidget::scroll(), moves existing
       // to fill the entire width of the widget                    // pixels on-screen and only paints new area.
       // (taking offset into account)                              // Also possible: call update() to redraw
       int x = -m_offset;                                           // the whole widget.
       while (x < width())                                          scroll(-1, 0);
       {                                                        } else {
           painter.drawText(x, 0, textWidth, height(),              // Event not from the timer we are
              Qt::AlignLeft | Qt::AlignVCenter, text());            // interested in -> pass to base class
           x += textWidth;                                          QWidget::timerEvent(event);
       }                                                        }
 }                                                          }

 void Ticker::showEvent(QShowEvent* /*event*/)              void Ticker::hideEvent(QHideEvent* /*event*/)
 {                                                          {
     // Starts a timer. Returned ID number can be               // Stop the timer
     // used to identify timer later                            killTimer(m_timerId);
     m_timerId = startTimer(30);                                m_timerId = 0;
 }                                                          }
Event Filters
• Look at / intercept events delivered to other object
    – e.g., dialogs filter key presses for widgets to modify Return-key handling

    – Set up through QObject::installEventFilter()
    – Target object gets events before monitored object
    – Accepts or rejects events: allow / deny further event processing

          monitoredObj->installEventFilter(targetObj);
Ways to Influence Event Handling I
1.   Incoming event first goes to virtual function QCoreApplication::notify()
     –    Override notify()
     –   Get all events before any event filters can intercept
     –   Only one subclass of QCoreApplication can be active at a time
2.   Install an event filter on QCoreApplication::instance()
     –    implement eventFilter()
     –   Get events after sent out by notify()
     –   As powerful as option 1, also allows multiple application-global event
         filters
Ways to Influence Event Handling II
3.    Event filter on target object
     –  implement eventFilter()
     – Gets all events (except Tab, Shift+Tab) before actual target object
4.    Event handler of target object
     –  override QObject::event()
     – Gets events after event filter
     – Don’t forget to call event handler of base class for unhandled events!
5.    Re-implement event handling functions
     –  implement paintEvent(), mousePressEvent()
     – Easiest, most common, but least powerful
Low Level Painting
Painting
• Low-level drawing handled through QPainter
• Draws on paint devices (QPaintDevice):
    – QWidget: most common use case
    – QImage: optimized for I/O and direct pixel manipulation
    – QPixmap: optimized for showing images on screen
            •   QBitmap: convenience for monochrome QPixmap –
                e.g., QCursor, QBrush, QRegion
    – QPicture: records and replays QPainter commands
    – QPrinter: paint on a printer
    – ...
QPainter
•   Can draw:
     – Geometric shapes with pen/brush
     – Fonts
     – Bezier curves
     – Images
•   Features:
     – Anti-aliasing
     – Alpha blending
     – Gradient filling
     – Vector paths
     – Linear transformations
Example: Drawing
  – Draws line between coordinates of two mouse clicks
  – Uses image to store drawing
  – Text written directly on Widget surface
Drawing
mainWidget.cpp
 MainWidget::MainWidget() {
    // Use standard colors of system
    setBackgroundRole(QPalette::Base);
    lastX = -1;
    lastY = -1;
    resize( 300, 200 );
    bgImg = new QPixmap(300, 200);
    bgImg->fill(QColor(255, 255, 255));
 }

 void MainWidget::mousePressEvent(QMouseEvent* event) {
     if (event->button() == Qt::LeftButton && lastX > -1 && lastY > -1) {
         // Create painter object for our image
         QPainter painter(bgImg);
         // Draw a line from previous pos to new position                   mainWidget.h
         painter.setPen(QPen(Qt::red, 3));
         painter.drawLine(lastX, lastY, event->x(), event->y());             class MainWidget : public QWidget {
         update();                                                           Q_OBJECT
     }                                                                       public:
     lastX = event->x();                                                        MainWidget();
     lastY = event->y();
 }
                                                                             protected:
                                                                                void mousePressEvent(QMouseEvent* event);
 void MainWidget::paintEvent(QPaintEvent* event) {                              void paintEvent(QPaintEvent* event);
     // Paint directly on the widget surface                                 private:
     QPainter painter(this);                                                    int lastX;
     // Draw the image to the widget                                            int lastY;
     painter.drawPixmap(0, 0, *bgImg);                                          QPixmap* bgImg;
     // Draw text on top of the image to the widget                          };
     painter.setPen(QPen(Qt::blue, 1));
     painter.drawText(5, 15, tr("Draw using left mouse button clicks"));
     painter.drawText(5, 30, tr("Set position with right mouse button"));
 }
The Graphics View
Framework
GraphicsView
Architecture
                             Scene


                    Item 1
                                              Item 6


           Item 2
                             Item 3
                                                 Item 7


                Item 4               Item 5
Graphics View Framework – Example
• Setting up a simple scene




 scene = new QGraphicsScene(0, 0, 400, 400);
 QGraphicsLineItem *wall = new QGraphicsLineItem
     (QLineF(0.0, 200.0, 100.0, 200.0));
 scene->addItem(wall);
 view = new QGraphicsView(scene);
 view->setRenderHint(QPainter::Antialiasing);
Items
•   QGraphicsItem subclasses
     – Pre-defined shapes (line, rectangle, polygon, path, etc.)
     – Text
     – Images
     – Widgets
     – Custom items
•   Supports
     – Painting
     – Transformations
     – Collision Detection
     – Interaction through event handlers
Using Widgets as Items?
• Possible through two ways:
   – QGraphicsWidget
       •   New subclass for widgets in QGraphicsScenes
       •   Resembles QWidget, only few limitations

   – QGraphicsProxyWidget
       •   Embeds a standard QWidget into QGraphicsScene
       •   Translates coordinate systems
       •   Automatically manages child widgets
       •   Not suitable for high performance scenarios
Proxy Widget – Example
    #include <QtGui>

     int main(int argc, char **argv)
     {
         QApplication app(argc, argv);

         QPushButton *testButton = new QPushButton("Hello World");

         QGraphicsScene scene;
         QGraphicsProxyWidget *proxy = scene.addWidget(testButton);
         proxy->rotate(-20.0);

         QGraphicsView view(&scene);
         view.show();

         return app.exec();
     }
Scene: QGraphicsScene
• Surface for managing items on a 2D surface
   – 3 layers: background, item layer, foreground
   – Scene can be parent of items, or items are children of other items
   – Manages items: position & transformation, visibility, collision, locate
      items
   – Propagates events to items
   – Indexes items with BSP tree by default
       •   Suitable for large scenes with relatively static items
View: QGraphicsView
• Widget that presents a scene
   – Multiple views for a single scene
      possible
   – Supports transformations
      (zooming, rotation, etc.)
   – Provides scroll bars if necessary
                                         Image Credit: Ricardo J. Reyes
                                                        Public Domain
   – By default uses 2D paint engine,
      possible to use OpenGL
Coordinate Systems
• Item Coordinates
   – Each item has its own coordinate system
   – Usually centered around its center point (0,0)
   – Relative to parent’s coordinates
• Scene Coordinates
   – Base coordinate system for all items
   – Describes position for all top-level items
• View Coordinates
   – Coordinates relative to the widget
Coordinate Mappings / Transformations
• Coordinate mappings with utility functions
   – mapToScene() / mapFromScene()
   – Available in view / scene / item classes
• Affine Transformations
   – Extra methods (rotate(), etc.)
   – QMatrix
QTransform transform;
transform.rotate(newPos.x() / 6.0, Qt::YAxis);
transform.rotate(newPos.y() / 6.0, Qt::XAxis);
baseItem->setTransform(transform);
Animation Framework
• Part of Qt Kinetic project (→ Qt 4.6)
    – Animate Qt properties of widgets and
      QObjects
    – Can be used on its own or with state
      machine
    – Supports easing curves, animation
      groups
Optimizing SVG
• Free tools
    – http://code.google.com/p/svgmin/
    – http://codedread.com/scour/

                            SVG Loading Time

 Optimized

   Original

              0   20   40    60     80   100   120   140   160   180
Pixel Images
• Most common pixel-based formats:
   – .png (Portable Network Graphics)
       •   Similar to .gif (which was patented until 2003 because of
           its LZW compression)
       •   Compression: works well for graphics, not so well for
           photos
       •   Transparency: support depends on device – 1 bit             increasing JPEG compression
           transparency or full alpha-channel.

   – .jpg (Joint Photographic Experts Group)
       •   Compression: for photos (wavelength), not for graphics
       •   Transparency: not supported                                        Image Credit: Ilmari_Karonen / Brianski
                                                                                                   Creative Commons
Save PNGs – File Size Reduction
   1.    Optimized export – Photoshop: Save for Web
   2.    Further optimization – Pngcrush: http://pmt.sourceforge.net/pngcrush/

                                                                Use as few colors as
                                                                   possible (fine
      No dithering                                              gradients compress
   (compression gets                                                  worse)
     more difficult)


   Transparenter Kanal
      You can set a
      transparency
      kann gesetzt
         channel
         werden
PNG Optimization – Example: 472 x 472 px




                  256 colours, no dither      64 colours, no dither                    8 colours, no dither
                         30,0 kB                     16,3 kB                                  6,3 kB

   Results:
   - Not much difference between 256
   and 64 colours (especially on a device
   display), but only half of the file size
   - Limits of optimization: 8 colours not
   enough
   - Dithering at 8 colours: same file size
   as visually better 64 colours image
                                                                8 colours, Diffusion dither
   → often, dithering is problematic!                                    15,9 kB
Thank You.

More Related Content

What's hot

IPC with Qt
IPC with QtIPC with Qt
IPC with Qt
Marius Bugge Monsen
 
Introduction to Qt programming
Introduction to Qt programmingIntroduction to Qt programming
Introduction to Qt programming
Dragos Tudor Acostachioaie
 
In-Depth Model/View with QML
In-Depth Model/View with QMLIn-Depth Model/View with QML
In-Depth Model/View with QML
ICS
 
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
ICS
 
Qt for beginners
Qt for beginnersQt for beginners
Qt for beginners
Sergio Shevchenko
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IV
ICS
 
Introduction to the Qt Quick Scene Graph
Introduction to the Qt Quick Scene GraphIntroduction to the Qt Quick Scene Graph
Introduction to the Qt Quick Scene Graph
ICS
 
Basics of Model/View Qt programming
Basics of Model/View Qt programmingBasics of Model/View Qt programming
Basics of Model/View Qt programming
ICS
 
Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4
ICS
 
Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6
ICS
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
ICS
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
Neera Mital
 
OpenShift Virtualization- Technical Overview.pdf
OpenShift Virtualization- Technical Overview.pdfOpenShift Virtualization- Technical Overview.pdf
OpenShift Virtualization- Technical Overview.pdf
ssuser1490e8
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring
Terry Cho
 
MVC MVVM MVVMC
MVC MVVM MVVMCMVC MVVM MVVMC
MVC MVVM MVVMC
Ng Hui Qin
 
Istio presentation jhug
Istio presentation jhugIstio presentation jhug
Istio presentation jhug
Georgios Andrianakis
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
Ynon Perek
 
Net framework
Net frameworkNet framework
Net framework
Saiteja Kaparthi
 
Grafana optimization for Prometheus
Grafana optimization for PrometheusGrafana optimization for Prometheus
Grafana optimization for Prometheus
Mitsuhiro Tanda
 

What's hot (20)

IPC with Qt
IPC with QtIPC with Qt
IPC with Qt
 
Introduction to Qt programming
Introduction to Qt programmingIntroduction to Qt programming
Introduction to Qt programming
 
In-Depth Model/View with QML
In-Depth Model/View with QMLIn-Depth Model/View with QML
In-Depth Model/View with QML
 
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
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
Qt for beginners
Qt for beginnersQt for beginners
Qt for beginners
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IV
 
Introduction to the Qt Quick Scene Graph
Introduction to the Qt Quick Scene GraphIntroduction to the Qt Quick Scene Graph
Introduction to the Qt Quick Scene Graph
 
Basics of Model/View Qt programming
Basics of Model/View Qt programmingBasics of Model/View Qt programming
Basics of Model/View Qt programming
 
Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4
 
Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
 
OpenShift Virtualization- Technical Overview.pdf
OpenShift Virtualization- Technical Overview.pdfOpenShift Virtualization- Technical Overview.pdf
OpenShift Virtualization- Technical Overview.pdf
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring
 
MVC MVVM MVVMC
MVC MVVM MVVMCMVC MVVM MVVMC
MVC MVVM MVVMC
 
Istio presentation jhug
Istio presentation jhugIstio presentation jhug
Istio presentation jhug
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
Net framework
Net frameworkNet framework
Net framework
 
Grafana optimization for Prometheus
Grafana optimization for PrometheusGrafana optimization for Prometheus
Grafana optimization for Prometheus
 

Similar to 05 - Qt External Interaction and Graphics

Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
account inactive
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9Shih-Hsiang Lin
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
NokiaAppForum
 
Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2
Emertxe Information Technologies Pvt Ltd
 
Qt & Webkit
Qt & WebkitQt & Webkit
Qt & Webkit
QT-day
 
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
account inactive
 
Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1
NokiaAppForum
 
CITi - PySide
CITi - PySideCITi - PySide
CITi - PySide
Daker Fernandes
 
The Ring programming language version 1.5.4 book - Part 64 of 185
The Ring programming language version 1.5.4 book - Part 64 of 185The Ring programming language version 1.5.4 book - Part 64 of 185
The Ring programming language version 1.5.4 book - Part 64 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 65 of 196
The Ring programming language version 1.7 book - Part 65 of 196The Ring programming language version 1.7 book - Part 65 of 196
The Ring programming language version 1.7 book - Part 65 of 196
Mahmoud Samir Fayed
 
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
ICS
 
Trisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorTrisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorEthanTu
 
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 78 of 210
The Ring programming language version 1.9 book - Part 78 of 210The Ring programming language version 1.9 book - Part 78 of 210
The Ring programming language version 1.9 book - Part 78 of 210
Mahmoud Samir Fayed
 
Spark Streaming - Meetup Data Analysis
Spark Streaming - Meetup Data AnalysisSpark Streaming - Meetup Data Analysis
Spark Streaming - Meetup Data Analysis
Sushmanth Sagala
 
The Ring programming language version 1.6 book - Part 73 of 189
The Ring programming language version 1.6 book - Part 73 of 189The Ring programming language version 1.6 book - Part 73 of 189
The Ring programming language version 1.6 book - Part 73 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 67 of 202
The Ring programming language version 1.8 book - Part 67 of 202The Ring programming language version 1.8 book - Part 67 of 202
The Ring programming language version 1.8 book - Part 67 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 48 of 84
The Ring programming language version 1.2 book - Part 48 of 84The Ring programming language version 1.2 book - Part 48 of 84
The Ring programming language version 1.2 book - Part 48 of 84
Mahmoud Samir Fayed
 

Similar to 05 - Qt External Interaction and Graphics (20)

Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
 
Qt Widgets In Depth
Qt Widgets In DepthQt Widgets In Depth
Qt Widgets In Depth
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
 
Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2
 
Qt & Webkit
Qt & WebkitQt & Webkit
Qt & Webkit
 
Qt Animation
Qt AnimationQt Animation
Qt Animation
 
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
 
Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1
 
CITi - PySide
CITi - PySideCITi - PySide
CITi - PySide
 
The Ring programming language version 1.5.4 book - Part 64 of 185
The Ring programming language version 1.5.4 book - Part 64 of 185The Ring programming language version 1.5.4 book - Part 64 of 185
The Ring programming language version 1.5.4 book - Part 64 of 185
 
The Ring programming language version 1.7 book - Part 65 of 196
The Ring programming language version 1.7 book - Part 65 of 196The Ring programming language version 1.7 book - Part 65 of 196
The Ring programming language version 1.7 book - Part 65 of 196
 
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
 
Trisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorTrisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptor
 
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.9 book - Part 71 of 210
 
The Ring programming language version 1.9 book - Part 78 of 210
The Ring programming language version 1.9 book - Part 78 of 210The Ring programming language version 1.9 book - Part 78 of 210
The Ring programming language version 1.9 book - Part 78 of 210
 
Spark Streaming - Meetup Data Analysis
Spark Streaming - Meetup Data AnalysisSpark Streaming - Meetup Data Analysis
Spark Streaming - Meetup Data Analysis
 
The Ring programming language version 1.6 book - Part 73 of 189
The Ring programming language version 1.6 book - Part 73 of 189The Ring programming language version 1.6 book - Part 73 of 189
The Ring programming language version 1.6 book - Part 73 of 189
 
The Ring programming language version 1.8 book - Part 67 of 202
The Ring programming language version 1.8 book - Part 67 of 202The Ring programming language version 1.8 book - Part 67 of 202
The Ring programming language version 1.8 book - Part 67 of 202
 
The Ring programming language version 1.2 book - Part 48 of 84
The Ring programming language version 1.2 book - Part 48 of 84The Ring programming language version 1.2 book - Part 48 of 84
The Ring programming language version 1.2 book - Part 48 of 84
 

More from Andreas Jakl

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented Reality
Andreas Jakl
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with Unity
Andreas Jakl
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App Management
Andreas Jakl
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSON
Andreas Jakl
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - Introduction
Andreas Jakl
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)
Andreas Jakl
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web Technologies
Andreas Jakl
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Andreas Jakl
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Andreas Jakl
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test Automation
Andreas Jakl
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Andreas Jakl
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
Andreas Jakl
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer Training
Andreas Jakl
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC Quickstart
Andreas Jakl
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App Scenarios
Andreas Jakl
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC Development
Andreas Jakl
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)
Andreas Jakl
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt Communication
Andreas Jakl
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt Data
Andreas Jakl
 
03 - Qt UI Development
03 - Qt UI Development03 - Qt UI Development
03 - Qt UI Development
Andreas Jakl
 

More from Andreas Jakl (20)

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented Reality
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with Unity
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App Management
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSON
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - Introduction
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web Technologies
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test Automation
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer Training
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC Quickstart
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App Scenarios
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC Development
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt Communication
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt Data
 
03 - Qt UI Development
03 - Qt UI Development03 - Qt UI Development
03 - Qt UI Development
 

Recently uploaded

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 

Recently uploaded (20)

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 

05 - Qt External Interaction and Graphics

  • 1. Qt – External Interaction and Graphics Andreas Jakl Senior Technical Consultant Forum Nokia 20 September, 2010 v3.0.0
  • 2. Contents – Events – Low Level Painting – Graphics View Framework – Optimizing Images
  • 4. Events • UI applications are event-based – Wait for user to interact – Then start working on the requested task • Alternative – Polling for status changes “Is the user pressing a button?” → Events save processing time, thus battery life Picture credits: Pearson Scott Foresman Public domain
  • 5. Events vs. Signals? • Signals – For using widgets – e.g., push button should return clicked() signal, not low-level mouse or key events • Events – For implementing widgets • Modifying existing widgets • New widgets – e.g., implement own push button: handle mouse and key events and emit clicked() signal when necessary
  • 6. Events and Signals • Mouse button’s way to become a clicked() signal QCoreApplication::exec() Mouse button Operating QEventLoop::exec() released system QEvent sent through event dispatcher QPushButton::event() QAbstractButton:: QAbstractButton::event() mouseReleasedEvent() QWidget::event() → emit clicked() signal QObject::event() Signal & slots connection Custom slot that handles button click
  • 7. Event Loop • Threads in Qt can have an event loop – Initial thread starts its loop through QCoreApplication::exec() – Other threads: QThread::exec() • Events – Derived from QEvent – Source: • Window system (QMouseEvent, QKeyEvent) • Generated by Qt itself (QTimerEvent) – Handled by QObject subclass (especially widgets)
  • 8. QEvent • Get type of event through QEvent::type() – 100+ events defined through enum values in Qt – Own events can be defined • Event is an instance of a QEvent subclass – Adds additional information about event – e.g., QMouseEvent: buttons, position, ...
  • 9. Handling Events in Widgets – Events delivered to event() function of QObject – Calls appropriate virtual event handler functions qwidget.cpp bool QWidget::event(QEvent *event) { Q_D(QWidget); // ... switch (event->type()) { case QEvent::MouseMove: mouseMoveEvent((QMouseEvent*)event); break; You only need to case QEvent::Paint: paintEvent((QPaintEvent*)event); override virtual, pre- defined handler method break; case QEvent::Close: closeEvent((QCloseEvent*)event); break; from QWidget base class // ... default: return QObject::event(event); } return true; }
  • 10. Example: Ticker • Scrolling text – 1 Pixel / 30 ms – Demonstrates Timer events • Handles 4 events – Paint event: manual drawing of the text – Timer event: regular call-backs – Show event: start timer when widget is shown – Hide event: end timer when widget becomes invisible
  • 11. Ticker – General Definition ticker.h ticker.cpp #ifndef TICKER_H #include "ticker.h" #define TICKER_H Ticker::Ticker(QWidget* parent) #include <QtGui> : QWidget(parent) { class Ticker : public QWidget m_offset = 0; { m_timerId = 0; Q_OBJECT } Q_PROPERTY(QString text READ text WRITE setText) void Ticker::setText(const QString &newText) public: { Ticker(QWidget* parent = 0); m_text = newText; void setText(const QString &newText); update(); QString text() const { return m_text; } updateGeometry(); QSize sizeHint() const; } protected: // Return recommended size of this widget void paintEvent(QPaintEvent* event); QSize Ticker::sizeHint() const void timerEvent(QTimerEvent* event); { void showEvent(QShowEvent* event); // Determine size required by the text void hideEvent(QHideEvent* event); // First argument isn't needed here -> 0 return fontMetrics().size(0, text()); private: } QString m_text; int m_offset; int m_timerId; }; #endif // TICKER_H
  • 12. Ticker – Event Handling ticker.cpp ticker.cpp void Ticker::paintEvent(QPaintEvent* /*event*/) void Ticker::timerEvent(QTimerEvent* event) { { QPainter painter(this); // Called by the system at intervals if (event->timerId() == m_timerId) // Get required width of the text { int textWidth = fontMetrics().width(text()); // Increase offset by 1 to simulate movement if (textWidth < 1) ++m_offset; return; if (m_offset >= fontMetrics().width(text())) m_offset = 0; // Draw the text as many times as necessary // Call to QWidget::scroll(), moves existing // to fill the entire width of the widget // pixels on-screen and only paints new area. // (taking offset into account) // Also possible: call update() to redraw int x = -m_offset; // the whole widget. while (x < width()) scroll(-1, 0); { } else { painter.drawText(x, 0, textWidth, height(), // Event not from the timer we are Qt::AlignLeft | Qt::AlignVCenter, text()); // interested in -> pass to base class x += textWidth; QWidget::timerEvent(event); } } } } void Ticker::showEvent(QShowEvent* /*event*/) void Ticker::hideEvent(QHideEvent* /*event*/) { { // Starts a timer. Returned ID number can be // Stop the timer // used to identify timer later killTimer(m_timerId); m_timerId = startTimer(30); m_timerId = 0; } }
  • 13. Event Filters • Look at / intercept events delivered to other object – e.g., dialogs filter key presses for widgets to modify Return-key handling – Set up through QObject::installEventFilter() – Target object gets events before monitored object – Accepts or rejects events: allow / deny further event processing monitoredObj->installEventFilter(targetObj);
  • 14. Ways to Influence Event Handling I 1. Incoming event first goes to virtual function QCoreApplication::notify() –  Override notify() – Get all events before any event filters can intercept – Only one subclass of QCoreApplication can be active at a time 2. Install an event filter on QCoreApplication::instance() –  implement eventFilter() – Get events after sent out by notify() – As powerful as option 1, also allows multiple application-global event filters
  • 15. Ways to Influence Event Handling II 3. Event filter on target object –  implement eventFilter() – Gets all events (except Tab, Shift+Tab) before actual target object 4. Event handler of target object –  override QObject::event() – Gets events after event filter – Don’t forget to call event handler of base class for unhandled events! 5. Re-implement event handling functions –  implement paintEvent(), mousePressEvent() – Easiest, most common, but least powerful
  • 17. Painting • Low-level drawing handled through QPainter • Draws on paint devices (QPaintDevice): – QWidget: most common use case – QImage: optimized for I/O and direct pixel manipulation – QPixmap: optimized for showing images on screen • QBitmap: convenience for monochrome QPixmap – e.g., QCursor, QBrush, QRegion – QPicture: records and replays QPainter commands – QPrinter: paint on a printer – ...
  • 18. QPainter • Can draw: – Geometric shapes with pen/brush – Fonts – Bezier curves – Images • Features: – Anti-aliasing – Alpha blending – Gradient filling – Vector paths – Linear transformations
  • 19. Example: Drawing – Draws line between coordinates of two mouse clicks – Uses image to store drawing – Text written directly on Widget surface
  • 20. Drawing mainWidget.cpp MainWidget::MainWidget() { // Use standard colors of system setBackgroundRole(QPalette::Base); lastX = -1; lastY = -1; resize( 300, 200 ); bgImg = new QPixmap(300, 200); bgImg->fill(QColor(255, 255, 255)); } void MainWidget::mousePressEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton && lastX > -1 && lastY > -1) { // Create painter object for our image QPainter painter(bgImg); // Draw a line from previous pos to new position mainWidget.h painter.setPen(QPen(Qt::red, 3)); painter.drawLine(lastX, lastY, event->x(), event->y()); class MainWidget : public QWidget { update(); Q_OBJECT } public: lastX = event->x(); MainWidget(); lastY = event->y(); } protected: void mousePressEvent(QMouseEvent* event); void MainWidget::paintEvent(QPaintEvent* event) { void paintEvent(QPaintEvent* event); // Paint directly on the widget surface private: QPainter painter(this); int lastX; // Draw the image to the widget int lastY; painter.drawPixmap(0, 0, *bgImg); QPixmap* bgImg; // Draw text on top of the image to the widget }; painter.setPen(QPen(Qt::blue, 1)); painter.drawText(5, 15, tr("Draw using left mouse button clicks")); painter.drawText(5, 30, tr("Set position with right mouse button")); }
  • 23. Architecture Scene Item 1 Item 6 Item 2 Item 3 Item 7 Item 4 Item 5
  • 24. Graphics View Framework – Example • Setting up a simple scene scene = new QGraphicsScene(0, 0, 400, 400); QGraphicsLineItem *wall = new QGraphicsLineItem (QLineF(0.0, 200.0, 100.0, 200.0)); scene->addItem(wall); view = new QGraphicsView(scene); view->setRenderHint(QPainter::Antialiasing);
  • 25. Items • QGraphicsItem subclasses – Pre-defined shapes (line, rectangle, polygon, path, etc.) – Text – Images – Widgets – Custom items • Supports – Painting – Transformations – Collision Detection – Interaction through event handlers
  • 26. Using Widgets as Items? • Possible through two ways: – QGraphicsWidget • New subclass for widgets in QGraphicsScenes • Resembles QWidget, only few limitations – QGraphicsProxyWidget • Embeds a standard QWidget into QGraphicsScene • Translates coordinate systems • Automatically manages child widgets • Not suitable for high performance scenarios
  • 27. Proxy Widget – Example #include <QtGui> int main(int argc, char **argv) { QApplication app(argc, argv); QPushButton *testButton = new QPushButton("Hello World"); QGraphicsScene scene; QGraphicsProxyWidget *proxy = scene.addWidget(testButton); proxy->rotate(-20.0); QGraphicsView view(&scene); view.show(); return app.exec(); }
  • 28. Scene: QGraphicsScene • Surface for managing items on a 2D surface – 3 layers: background, item layer, foreground – Scene can be parent of items, or items are children of other items – Manages items: position & transformation, visibility, collision, locate items – Propagates events to items – Indexes items with BSP tree by default • Suitable for large scenes with relatively static items
  • 29. View: QGraphicsView • Widget that presents a scene – Multiple views for a single scene possible – Supports transformations (zooming, rotation, etc.) – Provides scroll bars if necessary Image Credit: Ricardo J. Reyes Public Domain – By default uses 2D paint engine, possible to use OpenGL
  • 30. Coordinate Systems • Item Coordinates – Each item has its own coordinate system – Usually centered around its center point (0,0) – Relative to parent’s coordinates • Scene Coordinates – Base coordinate system for all items – Describes position for all top-level items • View Coordinates – Coordinates relative to the widget
  • 31. Coordinate Mappings / Transformations • Coordinate mappings with utility functions – mapToScene() / mapFromScene() – Available in view / scene / item classes • Affine Transformations – Extra methods (rotate(), etc.) – QMatrix QTransform transform; transform.rotate(newPos.x() / 6.0, Qt::YAxis); transform.rotate(newPos.y() / 6.0, Qt::XAxis); baseItem->setTransform(transform);
  • 32. Animation Framework • Part of Qt Kinetic project (→ Qt 4.6) – Animate Qt properties of widgets and QObjects – Can be used on its own or with state machine – Supports easing curves, animation groups
  • 33. Optimizing SVG • Free tools – http://code.google.com/p/svgmin/ – http://codedread.com/scour/ SVG Loading Time Optimized Original 0 20 40 60 80 100 120 140 160 180
  • 34. Pixel Images • Most common pixel-based formats: – .png (Portable Network Graphics) • Similar to .gif (which was patented until 2003 because of its LZW compression) • Compression: works well for graphics, not so well for photos • Transparency: support depends on device – 1 bit increasing JPEG compression transparency or full alpha-channel. – .jpg (Joint Photographic Experts Group) • Compression: for photos (wavelength), not for graphics • Transparency: not supported Image Credit: Ilmari_Karonen / Brianski Creative Commons
  • 35. Save PNGs – File Size Reduction 1. Optimized export – Photoshop: Save for Web 2. Further optimization – Pngcrush: http://pmt.sourceforge.net/pngcrush/ Use as few colors as possible (fine No dithering gradients compress (compression gets worse) more difficult) Transparenter Kanal You can set a transparency kann gesetzt channel werden
  • 36. PNG Optimization – Example: 472 x 472 px 256 colours, no dither 64 colours, no dither 8 colours, no dither 30,0 kB 16,3 kB 6,3 kB Results: - Not much difference between 256 and 64 colours (especially on a device display), but only half of the file size - Limits of optimization: 8 colours not enough - Dithering at 8 colours: same file size as visually better 64 colours image 8 colours, Diffusion dither → often, dithering is problematic! 15,9 kB