Widget Class Reference

#include <widget.h>

Inheritance diagram for Widget:

Inheritance graph
[legend]
Collaboration diagram for Widget:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 32 of file widget.h.

Public Slots

void animate ()

Public Member Functions

 Widget (Helper *helper, QWidget *parent)

Protected Member Functions

void paintEvent (QPaintEvent *event)

Private Attributes

Helperhelper
int elapsed


Constructor & Destructor Documentation

Widget::Widget ( Helper helper,
QWidget parent 
)

Definition at line 29 of file widget.cpp.

References elapsed, and QWidget::setFixedSize().

00030     : QWidget(parent), helper(helper)
00031 {
00032     elapsed = 0;
00033     setFixedSize(200, 200);
00034 }

Here is the call graph for this function:


Member Function Documentation

void Widget::animate (  )  [slot]

Definition at line 36 of file widget.cpp.

References elapsed, QWidget::repaint(), and QObject::sender().

00037 {
00038     elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
00039     repaint();
00040 }

void Widget::paintEvent ( QPaintEvent event  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.

A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.

Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.

Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.

When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.

The background can be set using setBackgroundRole() and setPalette().

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.

Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:

See also:
event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, {Analog Clock Example}

Reimplemented from QWidget.

Definition at line 42 of file widget.cpp.

References QPainter::Antialiasing, QPainter::begin(), elapsed, QPainter::end(), QWidget::event(), helper, Helper::paint(), and QPainter::setRenderHint().

00043 {
00044     QPainter painter;
00045     painter.begin(this);
00046     painter.setRenderHint(QPainter::Antialiasing);
00047     helper->paint(&painter, event, elapsed);
00048     painter.end();
00049 }

Here is the call graph for this function:


Member Data Documentation

Helper* Widget::helper [private]

Definition at line 46 of file widget.h.

Referenced by paintEvent().

int Widget::elapsed [private]

Definition at line 47 of file widget.h.

Referenced by animate(), paintEvent(), and Widget().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 20:13:09 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1