Contenu connexe Similaire à Qt Widget In-Depth (20) Plus de account inactive (20) Qt Widget In-Depth3. • Widgets and Window Systems
• Flags and Attributes
• The Future of Qt Widgets
5. • Widgets and Window Systems
• Window Systems
• Windows and Widgets
• Updates and Painting
• Events and Loops
6. • Widgets and Window Systems
• Window Systems
• Windows and Widgets
• Updates and Painting
• Events and Loops
7. QWS SunView
MiniGUI Metisse
Rio Microwindows
DM Fresco/Berlin
8 1/2 GEM ManaGeR
HP Windows OOHG
Xynth
MicroXwin Intuition
Y FBUI
NeWS
NeXT DPS Quartz
Wayland Twin
OPIE X
8. • X11
• Desktop Window Manager (MS Windows)
• Quartz Compositor (Mac OS X)
• QWS
• S60 Window Manager
14. Window System Qt Application
IPC #include<QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc,argv);
QWidget w;
w.show();
return a.exec();
}
15. • Widgets and Window Systems
• Window Systems
• Windows and Widgets
• Updates and Painting
• Events and Loops
21. • Widgets and Window Systems
• Window Systems
• Windows and Widgets
• Updates and Painting
• Events and Loops
22. Window System Paint Painting Code
#include<QtGui>
int main(int argc, char
*argv[])
{
QApplication a
(argc,argv);
QWidget w;
w.show();
return a.exec();
}
Update
23. Window System Backing Store Painting Code
#include<QtGui>
int main(int argc, char
*argv[])
{
QApplication a
(argc,argv);
QWidget w;
w.show();
return a.exec();
}
28. • Client Side • Server Side
• Window • Window
• Backing Store • Pixmap
• Pixmap
29. 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);
...
}
30. • Widgets and Window Systems
• Window Systems
• Windows and Widgets
• Updates and Painting
• Events and Loops
32. Input Event bool W::event(QEvent *e)
{
Any if (e->type() == t)
foobar();
return false;
}
33. Window System Socket Qt Event Dispatcher Event Handler
bool
W::event
(QEvent *e)
{
if (e-
>type() ==
Qt Event Loop
34. int QCoreApplication::exec()
{
...
QEventLoop eventLoop;
self->d_func()->in_exec = true;
self->d_func()->aboutToQuitEmitted = false;
int returnCode = eventLoop.exec();
...
}
38. 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);
...
}
40. 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
...
}
}
41. • select()
• poll status of file descriptors
• blocks until timeout
42. X11 Socket XLib Queue Qt Event Dispatcher Event Handler
bool
W::event
(QEvent *e)
{
if (e-
>type() ==
Qt Event Loop
43. postEvent() Qt Event Queue Event Loop Event Handler
#include<Q bool
tGui> W::event
int main(int (QEvent *e)
argc, char {
*argv[]) if (e-
{ >type() ==
44. sendEvent() Event Handler
#include<Q bool
tGui> W::event
int main(int (QEvent *e)
argc, char {
*argv[]) if (e-
{ >type() ==
55. • Input Events are propagated if
• event->isAccepted() == false
• receiver->event(e) == false
56. 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);
}
58. • Flags and Attributes
• Window Types
• Window Hints
• Widget States
• Widget Attributes
59. • QWidget
• QPaintDevice
• QObject
• QWindowSurface
60. • Flags and Attributes
• Window Types
• Window Hints
• Widget States
• Widget Attributes
62. • Dialog
• Sheet (Mac)
• Drawer (Mac)
• Popup
• ToolTip
• SplashScreen
• Desktop
• SubWindow (MDI)
64. • Flags and Attributes
• Window Types
• Window Hints
• Widget States
• Widget Attributes
65. • CustomizeWindowHint • MacWindowToolBarButtonHint
• WindowTitleHint • BypassGraphicsProxyWidget
• WindowSystemMenuHint • WindowShadeButtonHint
• WindowMinimizeButtonHint • WindowStaysOnTopHint
• WindowMaximizeButtonHint • WindowStaysOnBottomHint
• WindowMinMaxButtonHint • WindowOkButtonHint (WinCE)
• WindowCloseButtonHint • WindowCancelButtonHint (WinCE)
• WindowContextHelpButtonHint
66. • Flags and Attributes
• Window Types
• Window Hints
• Widget States
• Widget Attributes
67. • WindowState
• WindowNoState
• WindowMinimized
• WindowMaximized
• WindowFullScreen
• WindowActive
68. • Flags and Attributes
• Window Types
• Window Hints
• Widget States
• Widget Attributes
81. #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();
}
85. • QWidget
• Widget Hierarchy
• QGraphicsItem
• Scene Graph
86. • QWidget
• Alien Widgets
• Graphics Effects
• Disable Clipping ?
• Disable Move Events ?
• Transformations ?
97. Server Client
#include<QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc,argv);
QWidget w;
w.show();
return a.exec();
}
98. Server Protocol Client
?
#include<QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc,argv);
QWidget w;
w.show();
return a.exec();
}
100. Request #include<QtGui>
int main(int argc, char
*argv[])
{
QApplication a
(argc,argv);
QWidget w;
w.show();
return a.exec();
}
Response #include<QtGui>
int main(int argc, char
*argv[])
{
QApplication a
(argc,argv);
QWidget w;
w.show();
return a.exec();
}
101. Event bool W::event(QEvent *e)
{
if (e->type() == t)
foobar();
return false;
}
109. Source Code
• git://gitorious.org/+qt-developers/qt/lighthouse.git