qt widgets in depth

109
Qt Widgets In-Depth QWidget Under The Surface

Upload: marius-bugge-monsen

Post on 19-May-2015

2.341 views

Category:

Technology


9 download

TRANSCRIPT

Page 1: Qt Widgets In Depth

Qt Widgets In-DepthQWidget Under The Surface

Page 2: Qt Widgets In Depth

About Me

• Marius Bugge Monsen

• Qt Developer

• Qt Widgets Team Lead

Page 3: Qt Widgets In Depth

• Widgets and Window Systems

• Flags and Attributes

• The Future of Qt Widgets

Page 4: Qt Widgets In Depth

Widgets and Window Systemsby extranoise on flickr

Page 5: Qt Widgets In Depth

• Widgets and Window Systems

• Window Systems

• Windows and Widgets

• Updates and Painting

• Events and Loops

Page 6: Qt Widgets In Depth

• Widgets and Window Systems

• Window Systems

• Windows and Widgets

• Updates and Painting

• Events and Loops

Page 7: Qt Widgets In Depth

Rio

8 1/2Fresco/Berlin

FBUI

HP WindowsManaGeR

Metisse

MicroXwinNeWS

NeXT DPS

QWS

Quartz

SunView

TwinWayland X

Xynth

Y

DM

GEM

OPIE

Intuition

Microwindows

MiniGUI

OOHG

Page 8: Qt Widgets In Depth

• X11

• Desktop Window Manager (MS Windows)

• Quartz Compositor (Mac OS X)

• QWS

• S60 Window Manager

Page 9: Qt Widgets In Depth

Window Surface

Page 10: Qt Widgets In Depth

Surface

Surface

Page 11: Qt Widgets In Depth

Screen

Page 12: Qt Widgets In Depth

Window System

Page 13: Qt Widgets In Depth

Window System

Page 14: Qt Widgets In Depth

Window System Qt Application

#include<QtGui>int main(int argc, char *argv[]){ QApplication a(argc,argv); QWidget w; w.show(); return a.exec();}

IPC

Page 15: Qt Widgets In Depth

• Widgets and Window Systems

• Window Systems

• Windows and Widgets

• Updates and Painting

• Events and Loops

Page 16: Qt Widgets In Depth

Surface

Surface

Surface

Page 17: Qt Widgets In Depth

Surface

Surface Surface

Page 18: Qt Widgets In Depth
Page 19: Qt Widgets In Depth

Window

Widget

Widget

Page 20: Qt Widgets In Depth

Window

Page 21: Qt Widgets In Depth

• Widgets and Window Systems

• Window Systems

• Windows and Widgets

• Updates and Painting

• Events and Loops

Page 22: Qt Widgets In Depth

Paint#include<QtGui>int main(int argc, char *argv[]){ QApplication a(argc,argv); QWidget w; w.show(); return a.exec();}

Update

Window System Painting Code

Page 23: Qt Widgets In Depth

#include<QtGui>int main(int argc, char *argv[]){ QApplication a(argc,argv); QWidget w; w.show(); return a.exec();}

Backing StoreWindow System Painting Code

Page 24: Qt Widgets In Depth

Text

Text

Page 25: Qt Widgets In Depth

Text

Text

Page 26: Qt Widgets In Depth

• Client Side

• Top-Level Window

• Backing Store

• Pixmap

Page 27: Qt Widgets In Depth

• Server Side

• Window

• Pixmap

Page 28: Qt Widgets In Depth

• Client Side

• Window

• Backing Store

• Pixmap

• Server Side

• Window

• Pixmap

Page 29: Qt Widgets In Depth

void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, QPainter *sharedPainter, QWidgetBackingStore *backingStore){ ... //actually send the paint event QPaintEvent e(toBePainted); QCoreApplication::sendSpontaneousEvent(q, &e); ...}

Page 30: Qt Widgets In Depth

• Widgets and Window Systems

• Window Systems

• Windows and Widgets

• Updates and Painting

• Events and Loops

Page 31: Qt Widgets In Depth

• Spontaneous Events

• Application Events

Page 32: Qt Widgets In Depth

Any

Inputbool W::event(QEvent *e){ if (e->type() == t) foobar(); return false;}

Event

Page 33: Qt Widgets In Depth

Window System

Qt Event Loop

bool W::event(QEvent *e){ if (e->type() ==

Event HandlerSocket Qt Event Dispatcher

Page 34: Qt Widgets In Depth

int QCoreApplication::exec(){ ... QEventLoop eventLoop; self->d_func()->in_exec = true; self->d_func()->aboutToQuitEmitted = false; int returnCode = eventLoop.exec(); ...}

Page 35: Qt Widgets In Depth

int QEventLoop::exec(ProcessEventsFlags flags){ ... try { while (!d->exit) processEvents(flags | WaitForMoreEvents | EventLoopExec); } catch (...) { ... --d->threadData->loopLevel; return d->returnCode;}

Page 36: Qt Widgets In Depth

bool QEventLoop::processEvents(ProcessEventsFlags flags){ Q_D(QEventLoop); if (!d->threadData->eventDispatcher) return false; if (flags & DeferredDeletion) QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); return d->threadData->eventDispatcher->processEvents(flags);}

Page 37: Qt Widgets In Depth

bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags){ ... // we are awake, broadcast it emit awake(); QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData); ... nevents = d->doSelect(flags, tm); ...}

Page 38: Qt Widgets In Depth

int QEventDispatcherUNIXPrivate::doSelect( QEventLoop::ProcessEventsFlags flags, timeval *timeout){ ... // Process timers and socket notifiers - the common UNIX stuff ... nsel = q->select(highest + 1, &sn_vec[0].select_fds, &sn_vec[1].select_fds, &sn_vec[2].select_fds, timeout); ...}

Page 39: Qt Widgets In Depth

int QEventDispatcherUNIX::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout){ return qt_safe_select(nfds, readfds, writefds, exceptfds, timeout);}

Page 40: Qt Widgets In Depth

int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timeval *orig_timeout){ ... // loop and recalculate the timeout as needed int ret; forever { ret = ::select(nfds, fdread, fdwrite, fdexcept, &timeout); if (ret != -1 || errno != EINTR) return ret; // recalculate the timeout ... }}

Page 41: Qt Widgets In Depth

• select()

• poll status of file descriptors

• blocks until timeout

Page 42: Qt Widgets In Depth

X11

Qt Event Loop

bool W::event(QEvent *e){ if (e->type() ==

Event HandlerSocket Qt Event DispatcherXLib Queue

Page 43: Qt Widgets In Depth

Qt Event Queue Event Loopbool W::event(QEvent *e){ if (e->type() ==

Event Handler#include<QtGui>int main(int argc, char *argv[]){

postEvent()

Page 44: Qt Widgets In Depth

bool W::event(QEvent *e){ if (e->type() ==

Event Handler#include<QtGui>int main(int argc, char *argv[]){

sendEvent()

Page 45: Qt Widgets In Depth

• Event Propagation

Page 46: Qt Widgets In Depth

C

A

B

D

Page 47: Qt Widgets In Depth

D

C

A B

Page 48: Qt Widgets In Depth

D

C

A B

Page 49: Qt Widgets In Depth

D

C

A B

Page 50: Qt Widgets In Depth

D

C

A B

Page 51: Qt Widgets In Depth

bool QApplication::notify(QObject *receiver, QEvent *e){ ... bool res = false; if (!receiver->isWidgetType()) { res = d->notify_helper(receiver, e); } else switch (e->type()) { ...}

Page 52: Qt Widgets In Depth

• Widgets Propagate Events

Page 53: Qt Widgets In Depth

... case QEvent::StatusTip: case QEvent::WhatsThisClicked: { QWidget *w = static_cast<QWidget *>(receiver); while (w) { res = d->notify_helper(w, e); if ((res && e->isAccepted()) || w->isWindow()) break; w = w->parentWidget(); } } break; ...

Page 54: Qt Widgets In Depth

• Input Events Are Propagated

Page 55: Qt Widgets In Depth

• Input Events are propagated if

• event->isAccepted() == false

• receiver->event(e) == false

Page 56: Qt Widgets In Depth

bool QCoreApplicationPrivate::notify_helper(QObject *receiver, QEvent * event){ // send to all application event filters if (sendThroughApplicationEventFilters(receiver, event)) return true; // send to all receiver event filters if (sendThroughObjectEventFilters(receiver, event)) return true; // deliver the event return receiver->event(event);}

Page 57: Qt Widgets In Depth

Flags and Attributes

by Dan Queiroz on flickr

Page 58: Qt Widgets In Depth

• Flags and Attributes

• Window Types

• Window Hints

• Widget States

• Widget Attributes

Page 59: Qt Widgets In Depth

• QWidget

• QPaintDevice

• QObject

• QWindowSurface

Page 60: Qt Widgets In Depth

• Flags and Attributes

• Window Types

• Window Hints

• Widget States

• Widget Attributes

Page 61: Qt Widgets In Depth

• Window Types

• Widget

• Window

Page 62: Qt Widgets In Depth

• Dialog

• Sheet (Mac)

• Drawer (Mac)

• Popup

• ToolTip

• SplashScreen

• Desktop

• SubWindow (MDI)

Page 63: Qt Widgets In Depth
Page 64: Qt Widgets In Depth

• Flags and Attributes

• Window Types

• Window Hints

• Widget States

• Widget Attributes

Page 65: Qt Widgets In Depth

• CustomizeWindowHint

• WindowTitleHint

• WindowSystemMenuHint

• WindowMinimizeButtonHint

• WindowMaximizeButtonHint

• WindowMinMaxButtonHint

• WindowCloseButtonHint

• WindowContextHelpButtonHint

• MacWindowToolBarButtonHint

• BypassGraphicsProxyWidget

• WindowShadeButtonHint

• WindowStaysOnTopHint

• WindowStaysOnBottomHint

• WindowOkButtonHint (WinCE)

• WindowCancelButtonHint (WinCE)

Page 66: Qt Widgets In Depth

• Flags and Attributes

• Window Types

• Window Hints

• Widget States

• Widget Attributes

Page 67: Qt Widgets In Depth

• WindowState

• WindowNoState

• WindowMinimized

• WindowMaximized

• WindowFullScreen

• WindowActive

Page 68: Qt Widgets In Depth

• Flags and Attributes

• Window Types

• Window Hints

• Widget States

• Widget Attributes

Page 69: Qt Widgets In Depth

• Qt::Widget Attribute

• 124 Attributes

• setAttribute()

• testAttribute()

Page 70: Qt Widgets In Depth

• Qt::WA_AcceptDrops

• QWidget::setAcceptDrops()

Page 71: Qt Widgets In Depth

Tips and Tricksby robclimbing on flickr

Page 72: Qt Widgets In Depth

• Qt::WA_StaticContents

Page 73: Qt Widgets In Depth

Static Contents

Exposed

Expo

sed

Page 74: Qt Widgets In Depth

• Qt::WA_NoSystemBackground

Page 75: Qt Widgets In Depth

• Qt::WA_OpaquePaintEvent

Page 76: Qt Widgets In Depth

• QWidget::autoFillBackground

• Qt::WA_OpaquePaintEvent

Page 77: Qt Widgets In Depth
Page 78: Qt Widgets In Depth

• QWidget::scroll()

• QWidget::autoFillBackground

• Qt::WA_OpaquePaintEvent

Page 79: Qt Widgets In Depth

Scrolled

Exposed

Concealed

Page 80: Qt Widgets In Depth

• Qt::WA_TranslucentBackground

Page 81: Qt Widgets In Depth

#include <QtGui>

int main(int argc, char *argv[]){ QApplication app(argc, argv); QPixmap skin("transparency.png"); QLabel widget; widget.setPixmap(skin); widget.setWindowFlags(Qt::Window |Qt::CustomizeWindowHint |Qt::FramelessWindowHint); widget.setAttribute(Qt::WA_TranslucentBackground); widget.resize(skin.size()); widget.show(); return app.exec();}

Page 82: Qt Widgets In Depth
Page 83: Qt Widgets In Depth

The Future of Qt Widgetsby jeff_c on flickr

Page 84: Qt Widgets In Depth

• The story of two APIs ...

Page 85: Qt Widgets In Depth

• QWidget

• Widget Hierarchy

• QGraphicsItem

• Scene Graph

Page 86: Qt Widgets In Depth

• QWidget

• Alien Widgets

• Graphics Effects

• Disable Clipping ?

• Disable Move Events ?

• Transformations ?

Page 87: Qt Widgets In Depth

• Is it possible ?

Page 88: Qt Widgets In Depth

• Is it possible in Qt 4.x ?

Page 89: Qt Widgets In Depth

Thank you!

Questions?

Page 90: Qt Widgets In Depth

Bonus Material

Page 91: Qt Widgets In Depth

Qt Developer DaysWindow System

Page 92: Qt Widgets In Depth

Scene Graph IPCWindow Surface

Page 93: Qt Widgets In Depth

QGraphicsScene QTcpSocketQSharedMemory

Page 94: Qt Widgets In Depth

• Server

• Window

Page 95: Qt Widgets In Depth

• Server

• Connections

• Scene Graph

Page 96: Qt Widgets In Depth

• Window

• Surface

• Geometry

• Id

Page 97: Qt Widgets In Depth

Server

#include<QtGui>int main(int argc, char *argv[]){ QApplication a(argc,argv); QWidget w; w.show(); return a.exec();}

Client

Page 98: Qt Widgets In Depth

Server

#include<QtGui>int main(int argc, char *argv[]){ QApplication a(argc,argv); QWidget w; w.show(); return a.exec();}

Client

?

Protocol

Page 99: Qt Widgets In Depth

• Message

• Request

• Reply

• Event

Page 100: Qt Widgets In Depth

#include<QtGui>int main(int argc, char *argv[]){ QApplication a(argc,argv); QWidget w; w.show(); return a.exec();}

Request

#include<QtGui>int main(int argc, char *argv[]){ QApplication a(argc,argv); QWidget w; w.show(); return a.exec();}

Response

Page 101: Qt Widgets In Depth

bool W::event(QEvent *e){ if (e->type() == t) foobar(); return false;}

Event

Page 102: Qt Widgets In Depth

Lighthouse

Page 103: Qt Widgets In Depth

• Research!

• Qt Graphicssystem Interface

• Makes Qt ports easy

Page 104: Qt Widgets In Depth

• QGraphicsSystem

• QGraphicsSystemScreen

• QWindowSurface

Page 105: Qt Widgets In Depth

• QGraphicsSystem

• Window Surfaces

• Server Communication

Page 106: Qt Widgets In Depth

• QGraphicsSystemScreen

• Screen Information

• Depth

• Resolution

• Size

Page 107: Qt Widgets In Depth

• QWindowSurface

• Surface

• Geometry

• Id

Page 108: Qt Widgets In Depth

Demo

Page 109: Qt Widgets In Depth

• git://gitorious.org/+qt-developers/qt/lighthouse.git

Source Code