Logo Search packages:      
Sourcecode: qt4-x11 version File versions

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

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:

    extern void qt_x11_set_global_double_buffer(bool);

Note: In general, one should refrain from calling update() or repaint() {inside} of paintEvent(). For example, calling update() or repaint() on children inside a paintEvent() results in undefined behavior; the child may or may not get a paint event.

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

Reimplemented in QWizard, QGraphicsView, QHeaderView, QListView, QTableView, QTreeView, QX11EmbedContainer, QAbstractButton, QAbstractScrollArea, QAbstractSpinBox, QCheckBox, QComboBox, QDateTimeEdit, QDial, QDockWidget, QFocusFrame, QFrame, QGroupBox, QLabel, QLCDNumber, QLineEdit, QMdiArea, QMdiSubWindow, QMenu, QMenuBar, QProgressBar, QPushButton, QRadioButton, QRubberBand, QScrollBar, QSizeGrip, QSlider, QSplitterHandle, QStatusBar, QTabBar, QTabWidget, QTextBrowser, QTextEdit, QToolBar, QToolButton, QWorkspace, QGLWidget, Q3TabDialog, Q3Table, Q3Button, Q3ComboBox, Q3Frame, Q3Header, Q3MainWindow, Q3ProgressBar, Q3SpinWidget, and QSvgWidget.

Definition at line 6877 of file qwidget.cpp.

Referenced by QWidget::event(), and QMdiSubWindow::paintEvent().


Generated by  Doxygen 1.6.0   Back to index