HomeHome

Classes - Annotated - Tree - Functions - Home - Structure Qte

QWidget Class Reference


The QWidget class is the base class of all user interface objects. More...

#include <qwidget.h>

Inherits QObject and QPaintDevice.

Inherited by QButton, QComboBox, QDial, QDialog, QFrame, QGLWidget, QHeader, QLineEdit, QMainWindow, QNPWidget, QScrollBar, QSemiModal, QSizeGrip, QSlider, QStatusBar, QTabBar, QTabWidget, QToolBar, QWorkspace and QXtWidget.

List of all member functions.

Public Members

Public Slots

Static Public Members

Protected Members

Properties

TypeNameREADWRITEOptions
boolisTopLevelisTopLevel  
boolisModalisModal  
boolisPopupisPopup  
boolisDesktopisDesktop  
boolenabledisEnabledsetEnabled 
QRectgeometrygeometrysetGeometry 
QRectframeGeometryframeGeometry  
intxx  
intyy  
QPointpospos  
QSizeframeSizeframeSize  
QSizesizesizeresize DESIGNABLE false
intwidthwidth  
intheightheight  
QRectrectrect  
QRectchildrenRectchildrenRect  
QRegionchildrenRegionchildrenRegion  
QSizePolicysizePolicysizePolicysetSizePolicy 
QSizeminimumSizeminimumSizesetMinimumSize 
QSizemaximumSizemaximumSizesetMaximumSize 
intminimumWidthminimumWidthsetMinimumWidth STORED false
intminimumHeightminimumHeightsetMinimumHeight STORED false
intmaximumWidthmaximumWidthsetMaximumWidth STORED false
intmaximumHeightmaximumHeightsetMaximumHeight STORED false
QSizesizeIncrementsizeIncrementsetSizeIncrement 
QSizebaseSizebaseSizesetBaseSize 
BackgroundModebackgroundModebackgroundModesetBackgroundMode DESIGNABLE false
QColorbackgroundColorbackgroundColorsetBackgroundColor DESIGNABLE false
QColorforegroundColorforegroundColor  
QPixmapbackgroundPixmapbackgroundPixmapsetBackgroundPixmap DESIGNABLE false
QColorGroupcolorGroupcolorGroup  
QPalettepalettepalettesetPalette RESET unsetPalette
boolownPaletteownPalette  
QFontfontfontsetFont RESET unsetFont
boolownFontownFont  
QCursorcursorcursorsetCursor RESET unsetCursor
boolownCursorownCursor  
QStringcaptioncaptionsetCaption 
QPixmapiconiconsetIcon 
QStringiconTexticonTextsetIconText 
boolmouseTrackinghasMouseTrackingsetMouseTracking 
boolisActiveWindowisActiveWindow  
boolfocusEnabledisFocusEnabled  
FocusPolicyfocusPolicyfocusPolicysetFocusPolicy 
boolfocushasFocus  
boolupdatesEnabledisUpdatesEnabledsetUpdatesEnabled DESIGNABLE false
boolvisibleisVisible  
QRectvisibleRectvisibleRect  
boolhiddenisHidden  
boolminimizedisMinimized  
QSizesizeHintsizeHint  
QSizeminimumSizeHintminimumSizeHint  
QRectmicroFocusHintmicroFocusHint  
boolacceptDropsacceptDropssetAcceptDrops 
boolautoMaskautoMasksetAutoMask 
BackgroundOriginbackgroundOriginbackgroundOriginsetBackgroundOrigin 
boolcustomWhatsThiscustomWhatsThis  

Detailed Description

The QWidget class is the base class of all user interface objects.

The widget is the atom of the user interface: It receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a Z-order. A widget is clipped by its parent and by the widgets in front of it.

A widget that isn't embedded in a parent widget is called a top-level widget. Usually, top-level widgets are windows with a frame and a title bar (though it is also possible to create top level widgets without such decoration by the use of widget flags). In Qt, QMainWindow and the various subclasses of QDialog are the most common top-level windows.

A widget without a parent widget is always a top-level widget.

The opposite of top-level widgets are child widgets. Those are child windows in their parent widgets. You usually cannot distinguish a child widget from its parent visually. Most other widgets in Qt are useful only as child widgets. (You can make a e.g. button into a top-level widget, but most people prefer to put their buttons in e.g. dialogs.)

QWidget has many member functions, but some of them have little direct functionality - for example it has a font but never uses it itself. There are many subclasses which provide real functionality, as diverse as QPushButton, QListBox and QTabDialog.

Groups of functions:

Every widget's constructor accepts two or three standard arguments:

The tictac/tictac.cpp example program is good example of a simple widget. It contains a few event handlers (as all widgets must), a few custom routines that are peculiar to it (as all useful widgets must), and has a few children and connections. Everything it does is done in response to an event: This is by far the most common way to design GUI applications.

You will need to supply the content for your widgets yourself, but here is a brief run-down of the events, starting with the most common ones:

If your widget only contains child widgets, you probably do not need to implement any event handlers.

Widgets that accept keyboard input need to reimplement a few more event handlers:

Some widgets will need to reimplement some more obscure event handlers, too:

There are also some really obscure events. They are listed in qevent.h and you need to reimplement event() to handle them. The default implementation of event() handles Tab and shift-Tab (to move the keyboard focus), and passes on most other events to one of the more specialized handlers above.

When writing a widget, there are a few more things to look out for.

See also QEvent, QPainter, QGridLayout and QBoxLayout.

Examples: forever/forever.cpp layout/layout.cpp splitter/splitter.cpp customlayout/main.cpp progress/progress.cpp mainlyQt/editor.cpp iconview/main.cpp popup/popup.cpp xform/xform.cpp i18n/main.cpp menu/menu.cpp drawlines/connect.cpp qmag/qmag.cpp desktop/desktop.cpp scrollview/scrollview.cpp


Member Type Documentation

QWidget::BackgroundMode

This enum describes how the background of a widget changes, as the widget's palette changes.

The background is what the widget contains when paintEvent() is called. To minimize flicker, this should be the most common color or pixmap in the widget. For PaletteBackground, use colorGroup().brush( QColorGroup::Background ), and so on. There are also three special values, listed at the end:

FixedColor and FixedPixmap sometimes are just the right thing, but if you use them, make sure that your application looks right when the desktop color scheme has been changed. (On X11, a quick way to test is e.g. "./yourapp -bg paleblue". On Windows, you have to use the control panel.)

See also setBackgroundMode(), backgroundMode(), setBackgroundPixmap() and setBackgroundColor().

QWidget::BackgroundOrigin

This enum defines the origin used to draw a widget's background pixmap.

QWidget::FocusPolicy

This enum type defines the various policies a widget can have with respect to acquiring keyboard focus.

The policy can be:

QWidget::PropagationMode

This member is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

This enum used to determine how fonts and palette changes are propagated to children of a widget.


Member Function Documentation

QWidget::QWidget ( QWidget * parent=0, const char * name=0, WFlags f=0 )

Constructs a widget which is a child of parent, with the name name and widget flags set to f.

If parent is 0, the new widget becomes a top-level window. If parent is another widget, this widget becomes a child window inside parent. The new widget is deleted when parent is.

The name is sent to the QObject constructor.

The widget flags argument f is normally 0, but it can be set to customize the window frame of a top-level widget (i.e. parent must be zero). To customize the frame, set the WStyle_Customize flag OR'ed with any of the Qt::WidgetFlags.

Note that the X11 version of Qt may not be able to deliver all combinations of style flags on all systems. This is because on X11, Qt can only ask the window manager, and the window manager can override the application's settings. On Windows, Qt can set whatever flags you want.

Example:

    QLabel *spashScreen = new QLabel( 0, "mySplashScreen",
                                  WStyle_Customize | WStyle_NoBorder |
                                  WStyle_Tool );

QWidget::~QWidget ()

Destructs the widget.

All children of this widget are deleted first. The application exits if this widget is (was) the main widget.

bool QWidget::acceptDrops () const

Returns TRUE if drop events are enabled for this widget.

See also setAcceptDrops().

void QWidget::adjustSize () [virtual]

Adjusts the size of the widget to fit the contents.

Uses sizeHint() if valid (i.e if the size hint's width and height are equal to or greater than 0), otherwise sets the size to the children rectangle (the union of all child widget geometries).

See also sizeHint() and childrenRect().

Examples: xform/xform.cpp

Reimplemented in QMessageBox.

bool QWidget::autoMask () const

Returns whether or not the widget has the auto mask feature enabled.

See also setAutoMask(), updateMask(), setMask() and clearMask().

const QColor & QWidget::backgroundColor () const

Returns the background color of this widget, which is normally set implicitly by setBackgroundMode(), but can also be set explicitly by setBackgroundColor().

If there is a background pixmap (set using setBackgroundPixmap()), then the return value of this function is indeterminate.

See also setBackgroundColor(), foregroundColor(), colorGroup() and palette().

Examples: xform/xform.cpp grapher/grapher.cpp

void QWidget::backgroundColorChange ( const QColor & oldBackgroundColor ) [virtual protected]

This virtual function is called from setBackgroundColor(). oldBackgroundColor is the previous background color; you can get the new background color from backgroundColor().

Reimplement this function if your widget needs to know when its background color changes. You will almost certainly need to call this implementation of the function.

See also setBackgroundColor(), backgroundColor(), setPalette(), repaint() and update().

QWidget::BackgroundMode QWidget::backgroundMode() const

Returns the mode most recently set by setBackgroundMode(). The default is PaletteBackground.

See also BackgroundMode and setBackgroundMode().

QWidget::BackgroundOrigin QWidget::backgroundOrigin() const

Returns the current background origin.

See also setBackgroundOrigin().

const QPixmap * QWidget::backgroundPixmap () const

Returns the background pixmap if one has been set. If the widget has backgroundMode() NoBackground, the return value is a pixmap for which QPixmao:isNull() is true. If the widget has no pixmap is the background, the return value is a null pointer.

See also setBackgroundPixmap() and setBackgroundMode().

void QWidget::backgroundPixmapChange ( const QPixmap & oldBackgroundPixmap ) [virtual protected]

This virtual function is called from setBackgroundPixmap(). oldBackgroundPixmap is the previous background pixmap; you can get the new background pixmap from backgroundPixmap().

Reimplement this function if your widget needs to know when its background pixmap changes. You will almost certainly need to call this implementation of the function.

See also setBackgroundPixmap(), backgroundPixmap(), repaint() and update().

QSize QWidget::baseSize () const

Returns the widget base size

The base size is used to calculate a proper widget size in case the widget defines sizeIncrement().

See also setBaseSize() and setSizeIncrement().

QString QWidget::caption () const

Returns the widget caption. If no caption has been set (common for child widgets), this functions returns a null string.

See also setCaption(), icon(), iconText() and QString::isNull().

Examples: i18n/main.cpp

QRect QWidget::childrenRect () const

Returns the bounding rectangle of the widget's children.

Explicitely hidden children are excluded.

See also childrenRegion().

QRegion QWidget::childrenRegion () const

Returns the combined region of the widget's children geometry().

Explicitely hidden children are excluded.

See also childrenRect().

void QWidget::clearFocus () [slot]

Takes keyboard input focus from the widget.

If the widget has active focus, a focus out event is sent to this widget to tell it that it is about to lose the focus.

This widget must enable focus setting in order to get the keyboard input focus, i.e. it must call setFocusPolicy().

See also hasFocus(), setFocus(), focusInEvent(), focusOutEvent(), setFocusPolicy() and QApplication::focusWidget().

void QWidget::clearMask ()

Removes any mask set by setMask().

See also setMask().

void QWidget::clearWFlags ( WFlags f ) [protected]

Clears the widget flags f.

Widget flags are a combination of Qt::WidgetFlags.

See also testWFlags(), getWFlags() and setWFlags().

bool QWidget::close () [slot]

Closes this widget. Returns TRUE if the widget was closed, otherwise FALSE.

First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event. The default implementation of QWidget::closeEvent() accepts the close event.

The QApplication::lastWindowClosed() signal is emitted when the last visible top level widget is closed.

See also close(bool).

bool QWidget::close ( bool alsoDelete ) [virtual]

Closes this widget. Returns TRUE if the widget was closed, otherwise FALSE.

If alsoDelete is TRUE or the widget has the WDestructiveClose widget flag, the widget is also deleted. The widget can prevent itself from being closed by rejecting the QCloseEvent it gets.

The QApplication::lastWindowClosed() signal is emitted when the last visible top level widget is closed.

Note that closing the QApplication::mainWidget() terminates the application.

See also closeEvent(), QCloseEvent, hide(), QApplication::quit(), QApplication::setMainWidget() and QApplication::lastWindowClosed().

Examples: popup/popup.cpp

void QWidget::closeEvent ( QCloseEvent * e ) [virtual protected]

This event handler can be reimplemented in a subclass to receive widget close events.

The default implementation calls e->accept(), which hides this widget. See the QCloseEvent documentation for more details.

See also event(), hide(), close() and QCloseEvent.

Reimplemented in QPopupMenu, QProgressDialog and QDialog.

const QColorGroup & QWidget::colorGroup () const

Returns the current color group of the widget palette.

The color group is determined by the state of the widget.

A disabled widget returns the QPalette::disabled() color group, a widget in the window with keyboard focus returns the QPalette::active() color group, and all inactive widgets return the QPalette::inactive() color group.

See also palette() and setPalette().

void QWidget::constPolish () const [slot]

Ensures that the widget is properly initialized by calling polish().

Call constPolish() from functions like sizeHint() that depends on the widget being initialized, and that may be called before show().

Warning: Do not call constPolish() on a widget from inside that widget's constructor.

See also polish().

void QWidget::create ( WId window = 0, bool initializeWindow = TRUE, bool destroyOldWindow = TRUE ) [virtual protected]

Creates a new widget window if window is null, otherwise sets the widget's window to window.

Initializes the window (sets the geometry etc.) if initializeWindow is TRUE. If initializeWindow is FALSE, no initialization is performed. This parameter makes only sense if window is a valid window.

Destroys the old window if destroyOldWindow is TRUE. If destroyOldWindow is FALSE, you are responsible for destroying the window yourself (using platform native code).

The QWidget constructor calls create(0,TRUE,TRUE) to create a window for this widget.

const QCursor & QWidget::cursor () const

Returns the widget cursor. If no cursor has been set the parent widget's cursor is returned.

See also setCursor() and unsetCursor();.

void QWidget::customEvent ( QCustomEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive custom events. Custom events are user-defined events with a type value at least as large as the "User" item of the QEvent::Type enum, and is typically a QCustomEvent or QCustomEvent subclass.

See also event() and QCustomEvent.

bool QWidget::customWhatsThis () const [virtual]

Returns whether the widget wants to handle What's This help manually. The default implementation returns FALSE, which means the widget will not receive any events in Whats This mode.

The widget may leave Whats This mode by calling QWhatsThis::leaveWhatsThisMode(), with or without actually displaying any help text.

You may also reimplement customWhatsThis() if your widget is a so-called "passive interactor" that is supposed to work under all circumstances. Simply don't call QWhatsThis::leaveWhatsThisMode() in that case.

See also QWhatsThis::inWhatsThisMode() and QWhatsThis::leaveWhatsThisMode().

Reimplemented in QPopupMenu and QMenuBar.

void QWidget::destroy ( bool destroyWindow = TRUE, bool destroySubWindows = TRUE ) [virtual protected]

Frees up window system resources. Destroys the widget window if destroyWindow is TRUE.

destroy() calls itself recursively for all the child widgets, passing destroySubWindows for the destroyWindow parameter. To have more control over destruction of subwidgets, destroy subwidgets selectively first.

This function is usually called from the QWidget destructor.

void QWidget::dragEnterEvent ( QDragEnterEvent * ) [virtual protected]

This event handler is called when a drag is in progress and the mouse enters this widget.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also QTextDrag, QImageDrag and QDragEnterEvent.

Reimplemented in QMultiLineEdit and QLineEdit.

void QWidget::dragLeaveEvent ( QDragLeaveEvent * ) [virtual protected]

This event handler is called when a drag is in progress and the mouse leaves this widget.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also QTextDrag, QImageDrag and QDragLeaveEvent.

Reimplemented in QMultiLineEdit.

void QWidget::dragMoveEvent ( QDragMoveEvent * ) [virtual protected]

This event handler is called when a drag is in progress and the mouse enters this widget, and whenever it moves within the widget.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also QTextDrag, QImageDrag and QDragMoveEvent.

Reimplemented in QMultiLineEdit.

void QWidget::drawText ( int x, int y, const QString & str )

Writes str at position x,y.

The y position is the base line position of the text. The text is drawn using the default font and the default foreground color.

This function is provided for convenience. You will generally get more flexible results and often higher speed by using a a painter instead.

See also setFont(), foregroundColor() and QPainter::drawText().

void QWidget::drawText ( const QPoint & pos, const QString & str )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QWidget::dropEvent ( QDropEvent * ) [virtual protected]

This event handler is called when the drag is dropped on this widget.

See the Drag-and-drop documentation for an overview of how to provide drag-and-drop in your application.

See also QTextDrag, QImageDrag and QDropEvent.

Reimplemented in QLineEdit and QMultiLineEdit.

void QWidget::enabledChange ( bool oldEnabled ) [virtual protected]

This virtual function is called from setEnabled(). oldEnabled is the previous setting; you can get the new setting from isEnabled().

Reimplement this function if your widget needs to know when it becomes enabled or disabled. You will almost certainly need to update the widget using update().

The default implementation repaints the visible part of the widget.

See also setEnabled(), isEnabled(), repaint(), update() and visibleRect().

Reimplemented in QButton and QListView.

void QWidget::enterEvent ( QEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive widget enter events.

An event is sent to the widget when the mouse cursor enters the widget.

See also leaveEvent(), mouseMoveEvent() and event().

Reimplemented in QToolButton.

void QWidget::erase ( const QRegion & reg )

Erases the area defined by reg, without generating a paint event.

Child widgets are not affected.

Examples: drawlines/connect.cpp

void QWidget::erase ( int x, int y, int w, int h )

Erases the specified area (x,y,w,h) in the widget without generating a paint event.

If w is negative, it is replaced with width() - x. If h is negative, it is replaced width height() - y.

Child widgets are not affected.

See also repaint().

void QWidget::erase ()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This version erases the entire widget.

void QWidget::erase ( const QRect & r )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool QWidget::event ( QEvent * e ) [virtual protected]

This is the main event handler. You may reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

The main event handler first passes an event through all event filters that have been installed. If none of the filters intercept the event, it calls one of the specialized event handlers.

Key press/release events are treated differently from other events. event() checks for Tab and shift-Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or shift-Tab), event() calls keyPressEvent().

This function returns TRUE if it is able to pass the event over to someone, or FALSE if nobody wanted the event.

See also closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), keyPressEvent(), keyReleaseEvent(), leaveEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), QObject::event() and QObject::timerEvent().

Reimplemented from QObject.

QWidget * QWidget::find ( WId id ) [static]

Returns a pointer to the widget with window identifer/handle id.

The window identifier type depends by the underlying window system, see qwindowdefs.h for the actual definition. If there is no widget with this identifier, a null pointer is returned.

See also wmapper() and winId().

QFocusData * QWidget::focusData () [protected]

Returns a pointer to the focus data for this widget's top-level widget.

Focus data always belongs to the top-level widget. The focus data list contains all the widgets in this top-level widget that can accept focus, in tab order. An iterator points to the current focus widget (focusWidget() returns a pointer to this widget).

This information is useful for implementing advanced versions of focusNextPrevChild().

void QWidget::focusInEvent ( QFocusEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget.

A widget normally must setFocusPolicy() to something other than NoFocus in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)

The default implementation updates the widget if it accepts focus (see focusPolicy()). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.

See also focusOutEvent(), setFocusPolicy(), keyPressEvent(), keyReleaseEvent(), event() and QFocusEvent.

Reimplemented in QRadioButton, QSlider, QLineEdit, QTextView, QButton, QPushButton, QTabBar, QTable, QDial, QMultiLineEdit, QListBox, QComboBox, QGroupBox, QListView, QPopupMenu and QMenuBar.

bool QWidget::focusNextPrevChild ( bool next ) [virtual protected]

Finds a new widget to give the keyboard focus to, as appropriate for Tab/shift-Tab, and returns TRUE if is can find a new widget and FALSE if it can't,

If next is true, this function searches "forwards", if next is FALSE, "backwards".

Sometimes, you will want to reimplement this function. For example, a web browser might reimplement it to move its "current active link" forwards or backwards, and call QWidget::focusNextPrevChild() only when it reaches the last/first.

Child widgets call focusNextPrevChild() on their parent widgets, and only the top-level widget will thus make the choice of where to redirect focus. By overriding this method for an object, you thus gain control of focus traversal for all child widgets.

See also focusData().

Reimplemented in QScrollView, QMultiLineEdit, QPopupMenu and QButton.

void QWidget::focusOutEvent ( QFocusEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget.

A widget normally must setFocusPolicy() to something other than NoFocus in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)

The default implementation calls repaint() since the widget's colorGroup() changes from active to normal, so the widget probably needs repainting. It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.

See also focusInEvent(), setFocusPolicy(), keyPressEvent(), keyReleaseEvent(), event() and QFocusEvent.

Reimplemented in QButton, QMultiLineEdit, QMenuBar, QPopupMenu, QListView, QListBox, QTable, QTabBar, QTextView, QPushButton, QLineEdit, QDial and QSlider.

QWidget::FocusPolicy QWidget::focusPolicy() const

Returns QWidget::TabFocus if the widget accepts focus by tabbing, QWidget::ClickFocus if the widget accepts focus by clicking, QWidget::StrongFocus if it accepts both and QWidget::NoFocus if it does not accept focus at all.

See also isFocusEnabled(), setFocusPolicy(), focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent() and isEnabled().

QWidget * QWidget::focusProxy () const

Returns a pointer to the focus proxy, or 0 if there is no focus proxy.

See also setFocusProxy().

QWidget * QWidget::focusWidget () const

Returns the focus widget in this widget's window. This is not the same as QApplication::focusWidget(), which returns the focus widget in the currently active window.

QFont QWidget::font () const

Returns the font currently set for the widget.

fontInfo() tells you what font is actually being used.

As long as no special font has been set, this is either a special font for the widget class, the parent's font or - if this widget is a toplevel widget - the default application font.

See also setFont(), fontInfo(), fontMetrics() and QApplication::font().

Examples: xform/xform.cpp menu/menu.cpp grapher/grapher.cpp

void QWidget::fontChange ( const QFont & oldFont ) [virtual protected]

This virtual function is called from setFont(). oldFont is the previous font; you can get the new font from font().

Reimplement this function if your widget needs to know when its font changes. You will almost certainly need to update the widget using update().

The default implementation updates the widget including its geometry.

See also setFont(), font(), update() and updateGeometry().

Reimplemented in QMenuBar, QLabel and QGroupBox.

QFontInfo QWidget::fontInfo () const

Returns the font info for the widget's current font. Equivalent to QFontInto(widget->font()).

See also font(), fontMetrics() and setFont().

QFontMetrics QWidget::fontMetrics () const

Returns the font metrics for the widget's current font. Equivalent to QFontMetrics(widget->font()).

See also font(), fontInfo() and setFont().

Examples: xform/xform.cpp qmag/qmag.cpp drawdemo/drawdemo.cpp

QWidget::PropagationMode QWidget::fontPropagation() const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

The return value is meaningless

See also setFontPropagation().

const QColor & QWidget::foregroundColor () const

Returns the foreground color of this widget.

The foreground color is also accessible as colorGroup().foreground().

See also backgroundColor() and colorGroup().

QRect QWidget::frameGeometry () const

Returns the geometry of the widget, relative to its parent and including the window frame.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also geometry(), x(), y() and pos().

QSize QWidget::frameSize () const

Returns the size of the window system frame (for top level widgets).

const QRect & QWidget::geometry () const

Returns the geometry of the widget, relative to its parent widget and excluding the window frame.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also frameGeometry(), size() and rect().

Examples: qmag/qmag.cpp

WFlags QWidget::getWFlags () const [protected]

Returns the widget flags for this this widget.

Widget flags are a combination of Qt::WidgetFlags.

See also testWFlags(), setWFlags() and clearWFlags().

void QWidget::grabKeyboard ()

Grabs all keyboard input.

This widget will receive all keyboard events, independent of the active window.

Warning: Grabbing the keyboard might lock the terminal.

See also releaseKeyboard(), grabMouse() and releaseMouse().

void QWidget::grabMouse ()

Grabs the mouse input.

This widget will be the only one to receive mouse events until releaseMouse() is called.

Warning: Grabbing the mouse might lock the terminal.

It is almost never necessary to grab the mouse when using Qt since Qt grabs and releases it sensibly. In particular, Qt grabs the mouse when a button is pressed and keeps it until the last button is released.

Beware that only widgets actually shown on the screen may grab the mouse input.

See also releaseMouse(), grabKeyboard() and releaseKeyboard().

void QWidget::grabMouse ( const QCursor & cursor )

Grabs the mouse input and changes the cursor shape.

The cursor will assume shape cursor (for as long as the mouse focus is grabbed) and this widget will be the only one to receive mouse events until releaseMouse() is called().

Warning: Grabbing the mouse might lock the terminal.

See also releaseMouse(), grabKeyboard(), releaseKeyboard() and setCursor().

Examples: qmag/qmag.cpp

bool QWidget::hasFocus () const

Returns TRUE if this widget (or its focus proxy) has the keyboard input focus, otherwise FALSE.

Equivalent to qApp->focusWidget() == this.

See also setFocus(), clearFocus(), setFocusPolicy() and QApplication::focusWidget().

bool QWidget::hasMouseTracking () const

Returns TRUE if mouse tracking is enabled for this widget, or FALSE if mouse tracking is disabled.

See also setMouseTracking().

int QWidget::height () const

Returns the height of the widget, excluding the window frame.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also geometry(), width() and size().

Examples: xform/xform.cpp qmag/qmag.cpp grapher/grapher.cpp drawdemo/drawdemo.cpp

int QWidget::heightForWidth ( int w ) const [virtual]

Returns the preferred height for this widget, given the width w. The default implementation returns 0, indicating that the preferred height does not depend on the width.

Warning: Does not look at the widget's layout.

Reimplemented in QLabel, QMenuBar and QTextView.

void QWidget::hide () [virtual slot]

Hides the widget.

You almost never have to reimplement this function. If you need to do something after a widget is hidden, use hideEvent() instead.

See also isHhideEvent(), isHidden(), show(), showMinimized(), isVisible() and close().

Examples: progress/progress.cpp popup/popup.cpp xform/xform.cpp scrollview/scrollview.cpp

Reimplemented in QToolBar, QDialog, QPopupMenu and QMenuBar.

void QWidget::hideEvent ( QHideEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive widget hide events.

Hide events are sent to widgets right after they have been hidden.

See also event() and QHideEvent.

const QPixmap * QWidget::icon () const

Returns the widget icon pixmap, or null if no icon has been set.

See also setIcon(), iconText() and caption().

QString QWidget::iconText () const

Returns the widget icon text. If no icon text has been set (common for child widgets), this functions returns a null string.

See also setIconText(), icon(), caption() and QString::isNull().

bool QWidget::isActiveWindow () const

Returns TRUE if this widget is in the active window, i.e. the window that has keyboard focus.

When popup windows are visible, this function returns TRUE for both the active window and the popup.

See also setActiveWindow() and QApplication::activeWindow().

bool QWidget::isDesktop () const

Returns TRUE if the widget is a desktop widget, otherwise FALSE.

A desktop widget is also a top-level widget.

See also isTopLevel() and QApplication::desktop().

bool QWidget::isEnabled () const

Returns TRUE if the widget is enabled, or FALSE if it is disabled.

See also setEnabled().

bool QWidget::isEnabledTo ( QWidget * ancestor ) const

Returns TRUE if this widget would become enabled if ancestor is enabled.

This is the case if neither the widget itself nor every parent up to but excluding ancestor has been explicitly disabled.

isEnabledTo(0) is equivalent to isEnabled().

See also setEnabled() and isEnabled().

bool QWidget::isEnabledToTLW () const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

This function is deprecated. It is equivalent to isEnabled()

See also setEnabled() and isEnabled().

bool QWidget::isFocusEnabled () const

Returns TRUE if the widget accepts keyboard focus, or FALSE if it does not.

Keyboard focus is initially disabled (i.e. focusPolicy() == QWidget::NoFocus).

You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget's constructor. For instance, the QLineEdit constructor calls setFocusPolicy(QWidget::StrongFocus).

See also setFocusPolicy(), focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent() and isEnabled().

bool QWidget::isHidden () const

Returns TRUE if the widget is explicitly hidden, or FALSE if it is visible or would become visible if all its ancestors became visible.

See also hide(), show(), isVisible() and isVisibleTo().

bool QWidget::isMaximized () const

Returns TRUE if this widget is a top-level widget that is maximized, or else FALSE.

Note that due to limitations in some window-systems, this does not always report expected results (eg. if the user on X11 maximizes the window via the window manager, Qt has no way of telling this from any other resize). This will improve as window manager protocols advance.

See also showMaximized().

bool QWidget::isMinimized () const

Returns TRUE if this widget is a top-level widget that is minimized (iconified), or else FALSE.

See also showMinimized(), isVisible(), show(), hide() and showNormal().

bool QWidget::isModal () const

Returns TRUE if the widget is a modal widget, otherwise FALSE.

A modal widget is also a top-level widget.

See also isTopLevel() and QDialog.

bool QWidget::isPopup () const

Returns TRUE if the widget is a popup widget, otherwise FALSE.

A popup widget is created by specifying the widget flag WType_Popup to the widget constructor.

A popup widget is also a top-level widget.

See also isTopLevel().

bool QWidget::isTopLevel () const

Returns TRUE if the widget is a top-level widget, otherwise FALSE.

A top-level widget is a widget which usually has a frame and a caption (title bar). Popup and desktop widgets are also top-level widgets.

A top-level widgets can have a parent widget. It will then be grouped with its parent: deleted when the parent is deleted, minimized when the parent is minimized etc. If supported by the window manager, it will also have a common taskbar entry with its parent.

QDialog and QMainWindow widgets are by default top-level, even if a parent widget is specified in the constructor. This behavior is specified by the WType_TopLevel widget flag.

Child widgets are the opposite of top-level widgets.

See also topLevelWidget(), isModal(), isPopup(), isDesktop() and parentWidget().

bool QWidget::isUpdatesEnabled () const

Returns TRUE if updates are enabled, otherwise FALSE.

See also setUpdatesEnabled().

bool QWidget::isVisible () const

Returns TRUE if the widget itself is visible, or else FALSE.

Calling show() sets the widget to visible status if all its parent widgets up to the toplevel widget are visible. If an ancestor is not visible, the widget won't become visible until all its ancestors are shown.

Calling hide() hides a widget explicitly. An explicitly hidden widget will never become visible, even if all its ancestors become visible.

Iconified top-level widgets also have hidden status, as well as having isMinimized() return TRUE. Windows that live on another virtual desktop (on platforms that support this concept) also have hidden status.

This function returns TRUE if the widget currently is obscured by other windows on the screen, but would be visible if moved.

A widget receives show- and hide events when its visibility status changes. Between a hide and a show event, there is no need in wasting any CPU on preparing or displaying information to the user. A video application, for example, might simply stop generating new frames.

See also show(), hide(), isHidden(), isVisibleTo(), isMinimized(), showEvent() and hideEvent().

bool QWidget::isVisibleTo ( QWidget * ancestor ) const

Returns TRUE if this widget would become visible if ancestor is shown.

This is the case if neither the widget itself nor every parent up to but excluding ancestor has been explicitly hidden.

This function returns TRUE if the widget it is obscured by other windows on the screen, but would be visible if moved.

isVisibleTo(0) is very similar to isVisible(), with the exception that it does not cover the iconfied-case or the situation where the window lives on another virtual desktop.

See also show(), hide() and isVisible().

bool QWidget::isVisibleToTLW () const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

This function is deprecated. It is equivalent to isVisible()

See also show(), hide() and isVisible().

void QWidget::keyPressEvent ( QKeyEvent * e ) [virtual protected]

This event handler can be reimplemented in a subclass to receive key press events for the widget.

A widget must call setFocusPolicy() to accept focus initially and have focus in order to receive a key press event.

If you reimplement this handler, it is very important that you ignore() the event if you do not understand it, so that the widget's parent can interpret it.

The default implementation closes popup widgets if you hit escape. Otherwise the event is ignored.

See also keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event() and QKeyEvent.

Reimplemented in QListView, QTextBrowser, QListBox, QTextView, QMultiLineEdit, QDial, QComboBox, QTable, QSlider, QFileDialog, QButton, QLineEdit, QMessageBox, QDialog, QPopupMenu, QTabBar, QMenuBar and QScrollBar.

void QWidget::keyReleaseEvent ( QKeyEvent * e ) [virtual protected]

This event handler can be reimplemented in a subclass to receive key release events for the widget.

A widget must accept focus initially and have focus in order to receive a key release event.

If you reimplement this handler, it is very important that you ignore() the release if you do not understand it, so that the widget's parent can interpret it.

The default implementation ignores the event.

See also keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event() and QKeyEvent.

Reimplemented in QButton.

QWidget * QWidget::keyboardGrabber () [static]

Returns a pointer to the widget that is currently grabbing the keyboard input.

If no widget in this application is currently grabbing the keyboard, 0 is returned.

See also grabMouse() and mouseGrabber().

QLayoutQWidget::layout () const

Returns a pointer to the layout engine that manages the geometry of this widget's children.

If the widget does not have a layout, layout() returns a null pointer.

See also sizePolicy().

void QWidget::leaveEvent ( QEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive widget leave events.

A leave event is sent to the widget when the mouse cursor leaves the widget.

See also enterEvent(), mouseMoveEvent() and event().

Reimplemented in QSpinBox, QToolButton, QMultiLineEdit, QLineEdit and QMenuBar.

void QWidget::lower () [slot]

Lowers the widget to the bottom of the parent widget's stack.

If there are siblings of this widget that overlap it on the screen, this widget will be obscured by its siblings afterwards.

See also raise() and stackUnder().

QPoint QWidget::mapFrom ( QWidget * parent, const QPoint & pos ) const

Translates the widget coordinate pos from the coordinate system of parent to this widget's coordinate system, which must be non-null and be a parent widget of this.

See also mapTo(), mapFromParent() and mapFromGlobal().

QPoint QWidget::mapFromGlobal ( const QPoint & pos ) const

Translates the global screen coordinate pos to widget coordinates.

See also mapToGlobal(), mapFrom() and mapFromParent().

QPoint QWidget::mapFromParent ( const QPoint & pos ) const

Translates the parent widget coordinate pos to widget coordinates.

Same as mapFromGlobal() if the widget has no parent.

See also mapToParent(), mapFrom() and mapFromGlobal().

QPoint QWidget::mapTo ( QWidget * parent, const QPoint & pos ) const

Translates the widget coordinate pos to the coordinate system of parent, which must be non-null and be a parent widget of this.

See also mapFrom(), mapToParent() and mapToGlobal().

QPoint QWidget::mapToGlobal ( const QPoint & pos ) const

Translates the widget coordinate pos to global screen coordinates. For example,

 mapToGlobal(QPoint(0,0))
would give the global coordinates of the top-left pixel of the widget.

See also mapFromGlobal(), mapTo() and mapToParent().

Examples: popup/popup.cpp

QPoint QWidget::mapToParent ( const QPoint & pos ) const

Translates the widget coordinate pos to a coordinate in the parent widget.

Same as mapToGlobal() if the widget has no parent.

See also mapFromParent(), mapTo() and mapToGlobal().

int QWidget::maximumHeight () const

Returns the widget's maximum height.

See also maximumSize() and maximumWidth().

QSize QWidget::maximumSize () const

Returns the maximum widget size.

The widget cannot be resized to a larger size than the maximum widget size.

See also maximumWidth(), maximumHeight(), setMaximumSize(), minimumSize() and sizeIncrement().

int QWidget::maximumWidth () const

Returns the widget's maximum width.

See also maximumSize() and maximumHeight().

int QWidget::metric ( int m ) const [virtual protected]

Internal implementation of the virtual QPaintDevice::metric() function.

Use the QPaintDeviceMetrics class instead.

Reimplemented from QPaintDevice.

QRect QWidget::microFocusHint () const

Returns the currently set micro focus hint for this widget.

See also setMicroFocusHint().

int QWidget::minimumHeight () const

Returns the widget's minimum height.

See also minimumSize() and minimumWidth().

QSize QWidget::minimumSize () const

Returns the minimum widget size.

The widget cannot be resized to a smaller size than the minimum widget size.

If the returned minimum size equals (0,0) then it means that there are no constraints on the minimum size. However, Qt does nevertheless not allow you to shrink widgets to less than 1 pixel width/height.

See also maximumWidth(), maximumHeight(), setMinimumSize(), maximumSize() and sizeIncrement().

QSize QWidget::minimumSizeHint () const [virtual]

Returns a recommended minimum size for the widget, or an invalid size if no minimum size is recommended.

The default implementation returns an invalid size if there is no layout for this widget, the layout's minimum size otherwise.

See also QSize::isValid(), resize(), setMinimumSize() and sizePolicy().

Reimplemented in QListBox, QMenuBar, QMultiLineEdit, QTabWidget, QSplitter, QToolBar, QProgressBar, QSlider, QTabBar, QDial, QDialog, QLineEdit, QScrollView, QWidgetStack, QMainWindow, QLabel, QIconView and QListView.

int QWidget::minimumWidth () const

Returns the widget's minimum width.

See also minimumSize() and minimumHeight().

void QWidget::mouseDoubleClickEvent ( QMouseEvent * e ) [virtual protected]

This event handler can be reimplemented in a subclass to receive mouse double click events for the widget.

The default implementation generates a normal mouse press event.

Note that the widgets gets a mousePressEvent() and a mouseReleaseEvent() before the mouseDoubleClickEvent().

See also mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(), event() and QMouseEvent.

Reimplemented in QLineEdit, QMultiLineEdit, QComboBox and QListBox.

QWidget * QWidget::mouseGrabber () [static]

Returns a pointer to the widget that is currently grabbing the mouse input.

If no widget in this application is currently grabbing the mouse, 0 is returned.

See also grabMouse() and keyboardGrabber().

void QWidget::mouseMoveEvent ( QMouseEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive mouse move events for the widget.

If mouse tracking is switched off, mouse move events only occur if a mouse button is down while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is down.

QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user moves and clicks the mouse fast. This is a feature of the underlying window system, not Qt.

See also setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), event() and QMouseEvent.

Reimplemented in QLineEdit, QListBox, QComboBox, QDial, QSlider, QScrollBar, QSizeGrip, QMenuBar, QButton, QMultiLineEdit, QPopupMenu and QHeader.

void QWidget::mousePressEvent ( QMouseEvent * e ) [virtual protected]

This event handler can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

See also mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event() and QMouseEvent.

Reimplemented in QScrollBar, QPopupMenu, QComboBox, QSizeGrip, QListBox, QButton, QMenuBar, QSlider, QTabBar, QHeader, QLineEdit, QDial and QMultiLineEdit.

void QWidget::mouseReleaseEvent ( QMouseEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive mouse release events for the widget.

See also mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event() and QMouseEvent.

Reimplemented in QListBox, QHeader, QDial, QPopupMenu, QScrollBar, QSlider, QComboBox, QTabBar, QMenuBar, QMultiLineEdit, QButton and QLineEdit.

void QWidget::move ( int x, int y ) [virtual slot]

Moves the widget to the position (x,y) relative to the parent widget and including the window frame.

If the widget is visible, it receives a move event immediately. If the widget is not shown yet, it is guaranteed to receive an event before it actually becomes visible.

This function is virtual, and all other overloaded move() implementations call it.

Warning: If you call move() or setGeometry() from moveEvent(), you may see infinite recursion.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also pos(), resize(), setGeometry() and moveEvent().

Reimplemented in QDialog and QSemiModal.

void QWidget::move ( const QPoint & ) [slot]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Examples: popup/popup.cpp drawdemo/drawdemo.cpp

void QWidget::moveEvent ( QMoveEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive widget move events. When the widget receives this event, it is already at the new position.

The old position is accessible through QMoveEvent::oldPos().

See also resizeEvent(), event(), move() and QMoveEvent.

Reimplemented in QToolButton and QXtWidget.

bool QWidget::ownCursor () const

Returns whether the widget uses its own cursor or its parent widget's cursor.

bool QWidget::ownFont () const

Returns whether the widget uses its own font or its natural default font.

See also setFont() and unsetFont().

bool QWidget::ownPalette () const

Returns whether the widget uses its own palette or its natural default palette.

See also setPalette() and unsetPalette().

void QWidget::paintEvent ( QPaintEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive widget paint events.

When the paint event occurs, the update region QPaintEvent::region() normally has been cleared to the background color or pixmap. An exception is when repaint(FALSE) is called or the widget sets the WRepaintNoErase or WResizeNoErase flag. Inside the paint event handler, QPaintEvent::erased() carries this information.

For many widgets it is sufficient to redraw the entire widget each time, but some need to consider the update rectangle or region of the QPaintEvent to avoid slow update.

During paintEvent(), any QPainter you create on the widget will be clipped to at most the area covered by the update region.

update() and repaint() can be used to force a paint event.

See also event(), repaint(), update(), QPainter, QPixmap and QPaintEvent.

Reimplemented in QTabBar, QLineEdit, QSlider, QPopupMenu, QDial, QToolBar, QFrame, QTableView, QMainWindow, QButton, QGroupBox, QStatusBar, QComboBox, QTabDialog, QScrollBar, QSizeGrip, QHeader and QGLWidget.

const QPalette & QWidget::palette () const

Returns the widget palette.

As long as no special palette has been set, this is either a special palette for the widget class, the parent's palette or - if this widget is a toplevel widget - the default application palette.

See also setPalette(), colorGroup() and QApplication::palette().

void QWidget::paletteChange ( const QPalette & oldPalette ) [virtual protected]

This virtual function is called from setPalette(). oldPalette is the previous palette; you can get the new palette from palette().

Reimplement this function if your widget needs to know when its palette changes. You will almost certainly need to call this implementation of the function.

See also setPalette() and palette().

Reimplemented in QTextView.

QWidget::PropagationMode QWidget::palettePropagation() const

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

The return value is meaningless.

QWidget * QWidget::parentWidget () const

Returns a pointer to the parent of this widget, or a null pointer if it does not have any parent widget.

void QWidget::polish () [virtual slot]

Delayed initialization of a widget.

This function will be called after a widget has been fully created and before it is shown the very first time.

Polishing is useful for final initialization depending on an instantiated widget. This is something a constructor cannot guarantee since the initialization of the subclasses might not be finished.

After this function, the widget has a proper font and palette and QApplication::polish() has been called.

Remember to call QWidget's implementation when reimplementing this function.

See also constPolish() and QApplication::polish().

Examples: menu/menu.cpp

QPoint QWidget::pos () const

Returns the position of the widget in its parent widget, including the window frame.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also move(), frameGeometry(), x() and y().

Examples: qmag/qmag.cpp

void QWidget::raise () [slot]

Raises this widget to the top of the parent widget's stack.

If there are any siblings of this widget that overlap it on the screen, this widget will be visually in front of its siblings afterwards.

See also lower() and stackUnder().

QRect QWidget::rect () const

Returns the the internal geometry of the widget, excluding the window frame. rect() equals QRect(0,0,width(),height()).

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also size().

Examples: picture/picture.cpp menu/menu.cpp desktop/desktop.cpp grapher/grapher.cpp

void QWidget::releaseKeyboard ()

Releases the keyboard grab.

See also grabKeyboard(), grabMouse() and releaseMouse().

void QWidget::releaseMouse ()

Releases the mouse grab.

See also grabMouse(), grabKeyboard() and releaseKeyboard().

Examples: qmag/qmag.cpp

void QWidget::repaint ( const QRegion & reg, bool erase=TRUE ) [slot]

Repaints the widget directly by calling paintEvent() directly, unless updates are disabled or the widget is hidden.

Erases the widget region reg if erase is TRUE.

Use repaint if your widget needs to be repainted immediately, for example when doing some animation. In all other cases, update() is to be preferred. Calling update() many times in a row will generate a single paint event.

Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may see infinite recursion. The update() function never generates recursion.

See also update(), paintEvent(), setUpdatesEnabled() and erase().

Examples: xform/xform.cpp qmag/qmag.cpp

void QWidget::repaint ( int x, int y, int w, int h, bool erase=TRUE ) [slot]

Repaints the widget directly by calling paintEvent() directly, unless updates are disabled or the widget is hidden.

Erases the widget area (x,y,w,h) if erase is TRUE.

If w is negative, it is replaced with width() - x. If h is negative, it is replaced width height() - y.

Use repaint if your widget needs to be repainted immediately, for example when doing some animation. In all other cases, update() is to be preferred. Calling update() many times in a row will generate a single paint event.

Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may see infinite recursion. The update() function never generates recursion.

See also update(), paintEvent(), setUpdatesEnabled() and erase().

Examples: grapher/grapher.cpp

void QWidget::repaint () [slot]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This version erases and repaints the entire widget.

void QWidget::repaint ( bool erase ) [slot]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This version repaints the entire widget.

void QWidget::repaint ( const QRect & r, bool erase=TRUE ) [slot]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QWidget::reparent ( QWidget * parent, WFlags f, const QPoint & p, bool showIt=FALSE ) [virtual]

Reparents the widget. The widget gets a new parent, new widget flags (f, but as usual, use 0) at a new position in its new parent (p).

If showIt is TRUE, show() is called once the widget has been reparented.

If the new parent widget is in a different top-level widget, the reparented widget and its children are appended to the end of the TAB chain of the new parent widget, in the same internal order as before. If one of the moved widgets had keyboard focus, reparent() calls clearFocus() for that widget.

If the new parent widget is in the same top-level widget as the old parent, reparent doesn't change the TAB order or keyboard focus.

Warning: Reparenting widgets should be a real exception. In normal applications, you will almost never need it. Dynamic masks can be achieved much easier and cleaner with classes like QWidgetStack or on a higher abstraction level, QWizard.

See also getWFlags().

void QWidget::reparent ( QWidget * parent, const QPoint & p, bool showIt=FALSE )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

A convenience version of reparent that does not take widget flags as argument.

Calls reparent(parent, getWFlags()&~WType_Mask, p, showIt ).

void QWidget::resize ( int w, int h ) [virtual slot]

Resizes the widget to size w by h pixels.

If the widget is visible, it receives a resize event immediately. If the widget is not shown yet, it is guaranteed to receive an event before it actually becomes visible.

The size is adjusted if it is outside the minimum or maximum widget size.

This function is virtual, and all other overloaded resize() implementations call it.

Warning: If you call resize() or setGeometry() from resizeEvent(), you may see infinite recursion.

See also size(), move(), setGeometry(), resizeEvent(), minimumSize() and maximumSize().

Examples: aclock/main.cpp rot13/rot13.cpp checklists/main.cpp qmag/qmag.cpp buttongroups/main.cpp qwerty/main.cpp drawdemo/drawdemo.cpp

Reimplemented in QSemiModal and QDialog.

void QWidget::resize ( const QSize & ) [slot]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Examples: mainlyMotif/editor.cpp rangecontrols/main.cpp popup/popup.cpp listboxcombo/main.cpp dclock/main.cpp qfd/qfd.cpp fileiconview/main.cpp themes/main.cpp richtext/main.cpp scribble/main.cpp qmag/qmag.cpp scrollview/scrollview.cpp mainlyXt/editor.cpp listviews/main.cpp drawdemo/drawdemo.cpp

void QWidget::resizeEvent ( QResizeEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive widget resize events. When resizeEvent() is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize(), though.

The widget will be erased and receive a paint event immediately after processing the resize event. No drawing has to (and should) be done inside this handler.

Widgets that have been created with the WResizeNoErase flag will not be erased. Nevertheless, they will receive a paint event for their entire area afterwards. Again, no drawing needs to be done inside this handler.

The default implementation calls updateMask() if the widget has automatic masking enabled.

See also moveEvent(), event(), resize(), QResizeEvent and paintEvent().

Reimplemented in QComboBox, QTableView, QWorkspace, QProgressDialog, QLabel, QMultiLineEdit, QSlider, QSplitter, QLineEdit, QPushButton, QFileDialog, QMenuBar, QGroupBox, QTabDialog, QListBox, QTextView, QScrollView, QTable, QScrollBar, QGLWidget, QWidgetStack, QToolBar, QMessageBox, QCheckBox, QSpinBox, QMainWindow, QRadioButton, QStatusBar, QListView, QDial, QTabWidget, QTabBar, QFrame, QXtWidget and QDialog.

void QWidget::scroll ( int dx, int dy, const QRect & r )

Scrolls r dx pixels to the right and dy downwards. Both dx and dy may be negative.

If r is empty or invalid, the result is undefined.

After scrolling, scroll() sends a paint event for the the part of r that is read but not written. For example, when scrolling 10 pixels rightwards, the leftmost ten pixels of r need repainting. The paint event may be delivered immediately or later, depending on some heuristics.

This version of scroll() does not move the children of this widget.

See also QScrollView, erase() and bitBlt().

void QWidget::scroll ( int dx, int dy )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This version of the function scrolls the entire widget and moves the widget's children along with the scroll.

See also bitBlt() and QScrollView.

void QWidget::setAcceptDrops ( bool on ) [virtual]

Announces to the system that this widget may be able to accept drop events.

If the widgets is the desktop, this may fail if another application is using the desktop - you can call acceptDrops() to test if this occurs.

See also acceptDrops().

Examples: scrollview/scrollview.cpp

void QWidget::setActiveWindow () [virtual]

Sets the top-level widget containing this widget to be the active window.

An active window is a visible top-level window that has the keyboard input focus.

This function performs the same operation as clicking the mouse on the title bar of a top-level window. On X11, the result depends on the Window Manager. If you want to ensure that the window is stacked on top as well, call raise() in addition. Note that the window has be to visible, otherwise setActiveWindow() has no effect.

On Windows, if you are calling this when the application is not currently the active one then it will not make it the active window. It will flash the task bar entry blue to indicate that the window has done something. This is due to Microsoft not allowing an application to interrupt what the user is currently doing in another application.

See also isActiveWindow(), topLevelWidget() and show().

Reimplemented in QXtWidget.

void QWidget::setAutoMask ( bool enable ) [virtual]

Transparent widgets use a mask to define their visible region. QWidget has some built-in support to make the task of recalculating the mask easier. When setting auto mask to TRUE, updateMask() will be called whenever the widget is resized or changes its focus state.

Note: When you re-implement resizeEvent(), focusInEvent() or focusOutEvent() in your custom widgets and still want to ensure that the auto mask calculation works, you will have to add

    if ( autoMask() )
          updateMask();

at the end of your event handlers. Same holds for all member functions that change the appearance of the widget in a way that a recalculation of the mask is necessary.

While being a technically appealing concept, masks have one big drawback: when using complex masks that cannot be expressed easily with relatively simple regions, they tend to be very slow on some window systems. The classic example is a transparent label. The complex shape of its contents makes it necessary to represent its mask by a bitmap, which consumes both memory and time. If all you want is to blend the background of several neighboring widgets together seamlessly, you may probably want to use setBackgroundOrigin() rather than a mask.

See also autoMask(), updateMask(), setMask(), clearMask() and setBackgroundOrigin().

Examples: aclock/main.cpp

Reimplemented in QLabel.

void QWidget::setBackgroundColor ( const QColor & color ) [virtual]

Sets the widget to be cleared to the fixed color color before paintEvent() is called.

Note that using this function is very often a mistake. Here are the most common mistakes:

If you want to set the background color of a widget to one of the "usual" colors, setBackgroundMode() is usually the best function. For example, man widgets that usually use white backgrounds (and black text on it) can use this:

    thatWidget->setBackgroundMode( QWidget::PaletteBase );

If you want to change the color scheme of a widget, the setPalette() function is better suited. Here is how to set thatWidget to use a light green (RGB value 80, 255, 80) as background color, with shades of green used for all the 3D effects:

    thatWidget->setPalette( QPalette( QColor(80, 255, 80) ) );

A fixed background color sometimes is just the right thing, but if you use it, make sure that your application looks right when the desktop color scheme has been changed. (On X11, a quick way to test is e.g. "./yourapp -bg paleblue". On Windows, you have to use the control panel.)

See also setPalette(), QApplication::setPalette(), backgroundColor(), setBackgroundPixmap() and setBackgroundMode().

Examples: splitter/splitter.cpp hello/main.cpp customlayout/main.cpp xform/xform.cpp drawlines/connect.cpp desktop/desktop.cpp drawdemo/drawdemo.cpp

void QWidget::setBackgroundMode ( BackgroundMode m )

Tells the window system how to clear this widget when sending a paint event. In other words, this decides how the widgets looks when paintEvent() is called.

For most widgets the default (PaletteBackground, normally gray) suffices, but some need to use PaletteBase (the background color for text output, normally white) and a few need other colors.

QListBox, which is "sunken" and uses the base color to contrast with its environment, does this:

    setBackgroundMode( PaletteBase );

Note that two of the BackgroundMode values cannot be used with this function. For FixedPixmap, call setBackgroundPixmap() instead, and for FixedColor, call setBackgroundColor().

void QWidget::setBackgroundOrigin ( BackgroundOrigin origin )

Sets the widget's background to be drawn relative to origin, which is either of WidgetOrigin (the default) or ParentOrigin.

This makes a difference only if the widget has a background pixmap where the positioning matters. In such case, using ParentOrigin for several neighboring widgets makes the background blend together seamlessly.

See also backgroundOrigin(), backgroundPixmap() and setBackgroundMode().

void QWidget::setBackgroundPixmap ( const QPixmap & pixmap ) [virtual]

Sets the background pixmap of the widget to pixmap.

The background pixmap is tiled to cover the entire widget. Note that some widgets do not work well with a background pixmap, for example QLineEdit.

If pixmap is part of the widget's palette(), we recommend calling setBackgroundMode() instead.

A fixed background pixmap sometimes is just the right thing, but if you use it, make sure that your application looks right when the desktop color scheme has been changed. (On X11, a quick way to test is e.g. "./yourapp -bg paleblue". On Windows, you have to use the control panel.)

See also setBackgroundMode(), backgroundPixmap(), backgroundPixmapChange() and setBackgroundColor().

Examples: desktop/desktop.cpp

void QWidget::setBaseSize ( int basew, int baseh )

Sets the base size of the widget. The base size is important only in combination with size increments. See setSizeIncrement() for details.

See also baseSize().

void QWidget::setBaseSize ( const QSize & )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QWidget::setCaption ( const QString & caption ) [virtual slot]

Sets the window caption (title) to caption.

See also caption(), setIcon() and setIconText().

Examples: xml/tagreader-with-features/tagreader.cpp listbox/main.cpp forever/forever.cpp layout/layout.cpp splitter/splitter.cpp hello/main.cpp rangecontrols/main.cpp addressbook/main.cpp customlayout/main.cpp progress/progress.cpp aclock/main.cpp wizard/main.cpp rot13/rot13.cpp iconview/main.cpp popup/popup.cpp listboxcombo/main.cpp checklists/main.cpp tictac/main.cpp dclock/main.cpp application/main.cpp lineedits/main.cpp movies/main.cpp picture/picture.cpp mdi/main.cpp showimg/main.cpp qfd/qfd.cpp xform/xform.cpp tabdialog/main.cpp life/main.cpp themes/main.cpp tetrix/tetrix.cpp i18n/main.cpp menu/menu.cpp richtext/main.cpp drawlines/connect.cpp scribble/main.cpp dirview/main.cpp cursor/cursor.cpp action/main.cpp buttongroups/main.cpp helpviewer/main.cpp qwerty/main.cpp validator/main.cpp scrollview/scrollview.cpp listviews/main.cpp drawdemo/drawdemo.cpp tooltip/main.cpp progressbar/main.cpp

void QWidget::setCursor ( const QCursor & cursor ) [virtual]

Sets the widget cursor shape to cursor.

The mouse cursor will assume this shape when it's over this widget. See a list of predefined cursor objects with a range of useful shapes in the QCursor documentation.

An editor widget would for example use an I-beam cursor:

    setCursor( ibeamCursor );

See also cursor(), unsetCursor() and QApplication::setOverrideCursor().

Examples: cursor/cursor.cpp

void QWidget::setDisabled ( bool disable ) [slot]

Disables widget input events if disable is TRUE, otherwise enables input events.

An enabled widget receives keyboard and mouse events; a disabled widget does not. Note that an enabled widget receives keyboard events only when it is in focus.

Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled, you can reimplement the enabledChange() function.

Disabling a widget implicitely disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled.

See also setEnabled(), isEnabled(), isEnabledTo(), QKeyEvent, QMouseEvent and enabledChange().

void QWidget::setEnabled ( bool enable ) [virtual slot]

Enables widget input events if enable is TRUE, otherwise disables input events.

An enabled widget receives keyboard and mouse events; a disabled widget does not. Note that an enabled widget receives keyboard events only when it is in focus.

Some widgets display themselves differently when they are disabled. For example a button might draw its label grayed out. If your widget needs to know when it becomes enabled or disabled, you can reimplement the enabledChange() function.

Disabling a widget implicitely disables all its children. Enabling respectively enables all child widgets unless they have been explicitly disabled.

See also isEnabled(), isEnabledTo(), QKeyEvent, QMouseEvent and enabledChange().

Reimplemented in QScrollView.

void QWidget::setFixedHeight ( int h )

Sets both the minimum and maximum heights of the widget to h without changing the widths. Provided for convenience.

See also sizeHint(), minimumSize(), maximumSize(), setFixedSize() and more.

Examples: layout/layout.cpp

void QWidget::setFixedSize ( const QSize & s )

Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing or shrinking.

See also setMaximumSize() and setMinimumSize().

void QWidget::setFixedSize ( int w, int h )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QWidget::setFixedWidth ( int w )

Sets both the minimum and maximum width of the widget to w without changing the heights. Provided for convenience.

See also sizeHint(), minimumSize(), maximumSize(), setFixedSize() and more.

void QWidget::setFocus () [virtual slot]

Gives the keyboard input focus to the widget (or its focus proxy).

First, a focus out event is sent to the focus widget (if any) to tell it that it is about to lose the focus. Then a focus in event is sent to this widget to tell it that it just received the focus.

setFocus() gives focus to a widget regardless of its focus policy.

Warning: If you call setFocus() in a function which may itself be called from focusOutEvent() or focusInEvent(), you may see infinite recursion.

See also hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(), setFocusPolicy() and QApplication::focusWidget().

Examples: popup/popup.cpp xform/xform.cpp

void QWidget::setFocusPolicy ( FocusPolicy policy )

Enables or disables the keyboard focus for the widget.

The keyboard focus is initially disabled (i.e. policy == QWidget::NoFocus).

You must enable keyboard focus for a widget if it processes keyboard events. This is normally done from the widget's constructor. For instance, the QLineEdit constructor calls setFocusPolicy(QWidget::StrongFocus).

See also isFocusEnabled(), focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent() and isEnabled().

Examples: rot13/rot13.cpp

void QWidget::setFocusProxy ( QWidget * w ) [virtual]

Sets this widget's focus proxy to w. If w is 0, this function resets this widget to not have any focus proxy.

Some widgets, such as QComboBox, can "have focus," but create a child widget to actually handle the focus. QComboBox, for example, creates a QLineEdit.

setFocusProxy() sets the widget which will actually get focus when "this widget" gets it. If there is a focus proxy, focusPolicy(), setFocusPolicy(), setFocus() and hasFocus() all operate on the focus proxy.

See also focusProxy().

void QWidget::setFont ( const QFont & font ) [virtual]

Sets the font for the widget and informs all children about the change.

The fontInfo() function reports the actual font that is being used by the widget.

This code fragment sets a 12 point helvetica bold font:

    QFont f("Helvetica", 12, QFont::Bold);
    setFont( f );

See also font(), fontChange(), fontInfo(), fontMetrics(), unsetFont() and ownFont().

Examples: xform/xform.cpp grapher/grapher.cpp

Reimplemented in QFontDialog, QWizard, QPopupMenu and QTabDialog.

void QWidget::setFont ( const QFont & font, bool )

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use setFont( const QFont& font) instead.

Examples: hello/main.cpp xform/xform.cpp

void QWidget::setFontPropagation ( PropagationMode )

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Calling this function has no effect.

void QWidget::setGeometry ( int x, int y, int w, int h ) [virtual slot]

Sets the widget geometry to w by h, positioned at x,y in its parent widget.

If the widget is visible, it receives a move event and/or resize event immediately. If the widget is not shown yet, it is guaranteed to receive appropriate events before it actually becomes visible.

The size is adjusted if it is outside the minimum or maximum widget size.

This function is virtual, and all other overloaded setGeometry() implementations call it.

Warning: If you call setGeometry() from resizeEvent() or moveEvent(), you may see infinite recursion.

See also geometry(), move(), resize(), moveEvent(), resizeEvent(), minimumSize() and maximumSize().

Reimplemented in QDialog.

void QWidget::setGeometry ( const QRect & ) [virtual slot]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Examples: popup/popup.cpp i18n/main.cpp qmag/qmag.cpp drawdemo/drawdemo.cpp

Reimplemented in QDialog.

void QWidget::setIcon ( const QPixmap & pixmap ) [virtual slot]

Sets the window icon to pixmap.

See also icon(), setIconText(), setCaption() and Setting the Application Icon

Reimplemented in QMessageBox.

void QWidget::setIconText ( const QString & iconText ) [virtual slot]

Sets the text of the window's icon to iconText.

See also iconText(), setIcon() and setCaption().

void QWidget::setKeyCompression ( bool compress ) [virtual protected]

Enables key event compression, if enable is TRUE, and disables it if enable is FALSE.

By default key compression is off, so widgets receive one key press event for each key press (or more, since autorepeat is usually on). If you turn it on and your program doesn't keep up with key input, Qt tries to compress key events so that more than one character can be processed in each event.

For example, a word processor widget might receive 2, 3 or more characters in each QKeyEvent::text(), if the layout recalculation takes too long for the CPU.

If a widget supports multiple character unicode input, it is always safe to turn the compression on.

See also QKeyEvent::text();.

void QWidget::setMask ( const QBitmap & bitmap ) [virtual]

Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. If the region includes pixels outside the rect() of the widget, window system controls in that area may or may not be visible, depending on the platform.

Note that this effect can be slow if the region is particularly complex.

See also setMask(const, QRegion&) and clearMask().

void QWidget::setMask ( const QRegion & region ) [virtual]

Causes only the parts of the widget which overlap region to be visible. If the region includes pixels outside the rect() of the widget, window system controls in that area may or may not be visible, depending on the platform.

Note that this effect can be slow if the region is particularly complex.

See also setMask(QBitmap) and clearMask().

void QWidget::setMaximumHeight ( int h )

Sets the maximum height of the widget to h without changing the width. Provided for convenience.

See also sizeHint(), minimumSize(), maximumSize(), setFixedSize() and more.

Examples: splitter/splitter.cpp

void QWidget::setMaximumSize ( int maxw, int maxh ) [virtual]

Sets the maximum size of the widget to w by h pixels.

The widget cannot be resized to a larger size than the maximum widget size. The widget's size is forced to the maximum size if the current size is greater.

See also maximumSize(), setMinimumSize(), setSizeIncrement(), resize() and size().

void QWidget::setMaximumSize ( const QSize & size )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QWidget::setMaximumWidth ( int w )

Sets the maximum width of the widget to w without changing the height. Provided for convenience.

See also sizeHint(), minimumSize(), maximumSize(), setFixedSize() and more.

void QWidget::setMicroFocusHint ( int x, int y, int width, int height, bool text=TRUE ) [virtual protected]

When a widget gets focus, it should call setMicroFocusHint for some appropriate position and size - x, y and w by h. This has no visual effect, it just provides hints to any system-specific input handling tools.

The text argument should be TRUE if this is a position for text input.

In the Windows version of Qt, this method sets the system caret, which is used for user Accessibility focus handling. If text is TRUE, it also sets the IME composition window in Far East Asian language input systems.

In the X11 version of Qt, if text is TRUE, this method sets the XIM "spot" point for complex language input handling.

See also microFocusHint().

void QWidget::setMinimumHeight ( int h )

Sets the minimum height of the widget to h without changing the width. Provided for convenience.

See also sizeHint(), minimumSize(), maximumSize(), setFixedSize() and more.

void QWidget::setMinimumSize ( int minw, int minh ) [virtual]

Sets the minimum size of the widget to w by h pixels.

The widget cannot be resized to a smaller size than the minimum widget size. The widget's size is forced to the minimum size if the current size is smaller.

If you use a layout inside the widget, the minimum size will be set by the layout and not by setMinimumSize, unless you set the layouts resize mode to QLayout::FreeResize.

See also minimumSize(), setMaximumSize(), setSizeIncrement(), resize(), size() and QLayout::setResizeMode().

Examples: splitter/splitter.cpp menu/menu.cpp qmag/qmag.cpp

void QWidget::setMinimumSize ( const QSize & size )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QWidget::setMinimumWidth ( int w )

Sets the minimum width of the widget to w without changing the height. Provided for convenience.

See also sizeHint(), minimumSize(), maximumSize(), setFixedSize() and more.

void QWidget::setMouseTracking ( bool enable ) [virtual slot]

Enables mouse tracking if enable is TRUE, or disables it if enable is FALSE.

If mouse tracking is disabled (default), this widget only receives mouse move events when at least one mouse button is pressed down while the mouse is being moved.

If mouse tracking is enabled, this widget receives mouse move events even if no buttons are pressed down.

See also hasMouseTracking(), mouseMoveEvent() and QApplication::setGlobalMouseTracking().

Examples: popup/popup.cpp qmag/qmag.cpp

Reimplemented in QGLWidget.

void QWidget::setName ( const char * name ) [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QObject.

void QWidget::setPalette ( const QPalette & p, bool )

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Use setPalette( const QPalette& p ) instead.

void QWidget::setPalette ( const QPalette & palette ) [virtual]

Sets the widget palette to palette and informs all children about the change.

See also QApplication::setPalette(), palette(), paletteChange(), unsetPalette(), ownPalette() and colorGroup().

void QWidget::setPalettePropagation ( PropagationMode )

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

Calling this function has no effect.

void QWidget::setSizeIncrement ( int w, int h ) [virtual]

Sets the size increment of the widget. When the user resizes the window, the size will move in steps of w pixels horizontally and h pixels vertically, with baseSize() as basis. Preferred widget sizes are therefore for non-negative integers i and j:

  width = baseSize().width() + i * sizeIncrement().width();
  height = baseSize().height() + j * sizeIncrement().height();

Note that while you can set the size increment for all widgets, it has no effect except for top-level widgets.

Warning: The size increment has no effect under Windows, and may be disregarded by the window manager on X.

See also sizeIncrement(), setMinimumSize(), setMaximumSize(), resize() and size().

void QWidget::setSizeIncrement ( const QSize & )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QWidget::setSizePolicy ( QSizePolicy policy )

Sets the size policy for this widget to policy. The size policy specifies the default layout behaviour.

The default policy is Preferred/Preferred, which means that the widget can be freely resized, but prefers to be the size sizeHint() returns. Button-like widgets set the size policy to specify that they may stretch horizontally, but are fixed vertically. The same applies to lineedit controls (such as QLineEdit, QSpinBox or an editable QComboBox) and other horizontally orientated widgets (such as QProgressBar). A QToolButton on the other hand wants to be squared, therefore it allows growth in both directions. Widgets that support different directions (such as QSlider, QScrollBar or QHeader) specify stretching in the respective direction only. Widgets that can provide scrollbars (usually subclasses of QScrollView) tend to specify that they can use additional space, and that they can survive on less than sizeHint().

See also sizeHint(), QLayout, QSizePolicy and updateGeometry().

void QWidget::setStyle ( QStyle * style )

Sets the widget's GUI style to style. Ownership of the style object is not transferred.

If no style is set, the widget uses the application's style QApplication::style() instead.

Setting a widget's style has no effect on existing or future child widgets.

Warning: This function is particularly useful for demonstration purposes, where you want to show Qt's styling capabilities. Real applications should stay away from it and use one consistent GUI style instead.

See also style(), QStyle, QApplication::style() and QApplication::setStyle().

Examples: grapher/grapher.cpp

void QWidget::setTabOrder ( QWidget * first, QWidget * second ) [static]

Moves the second widget around the ring of focus widgets so that keyboard focus moves from first widget to second widget when Tab is pressed.

Note that since the tab order of the second widget is changed, you should order a chain like this:

    setTabOrder(a, b ); // a to b
    setTabOrder(b, c ); // a to b to c
    setTabOrder(c, d ); // a to b to c to d

not like this:

    setTabOrder(c, d); // c to d
    setTabOrder(a, b); // a to b AND c to d
    setTabOrder(b, c); // a to b to c, but not c to d

If either first or second has a focus proxy, setTabOrder() substitutes its/their proxies.

See also setFocusPolicy() and setFocusProxy().

Examples: customlayout/main.cpp

void QWidget::setUpdatesEnabled ( bool enable ) [virtual slot]

Enables widget updates if enable is TRUE, or disables widget updates if enable is FALSE.

Calling update() and repaint() has no effect if updates are disabled. Paint events from the window system are processed normally even if updates are disabled.

This function is normally used to disable updates for a short period of time, for instance to avoid screen flicker during large changes.

Example:

    setUpdatesEnabled( FALSE );
    bigVisualChanges();
    setUpdatesEnabled( TRUE );
    repaint();

See also isUpdatesEnabled(), update(), repaint() and paintEvent().

Reimplemented in QHeader.

void QWidget::setWFlags ( WFlags f ) [virtual protected]

Sets the widget flags f.

Widget flags are a combination of Qt::WidgetFlags.

See also testWFlags(), getWFlags() and clearWFlags().

void QWidget::show () [virtual slot]

Shows the widget and its child widgets.

If its size or position has changed, Qt guarantees that a widget gets move and resize events just before the widget is shown.

You almost never have to reimplement this function. If you need to change some settings before a widget is shown, use showEvent() instead. If you need to do some delayed initialization use polish().

See also showEvent(), hide(), showMinimized(), showMaximized(), showNormal(), isVisible() and polish().

Examples: xml/tagreader-with-features/tagreader.cpp listbox/main.cpp forever/forever.cpp layout/layout.cpp splitter/splitter.cpp hello/main.cpp rangecontrols/main.cpp customlayout/main.cpp progress/progress.cpp aclock/main.cpp rot13/rot13.cpp popup/popup.cpp listboxcombo/main.cpp checklists/main.cpp tictac/main.cpp dclock/main.cpp lineedits/main.cpp movies/main.cpp picture/picture.cpp biff/main.cpp showimg/main.cpp xform/xform.cpp life/main.cpp tetrix/tetrix.cpp i18n/main.cpp menu/menu.cpp richtext/main.cpp drawlines/connect.cpp qmag/qmag.cpp cursor/cursor.cpp buttongroups/main.cpp qwerty/main.cpp validator/main.cpp scrollview/scrollview.cpp listviews/main.cpp drawdemo/drawdemo.cpp tooltip/main.cpp progressbar/main.cpp

Reimplemented in QWidgetStack, QToolBar, QMainWindow, QSemiModal, QWizard, QMenuBar, QProgressBar, QPopupMenu, QTabBar, QTableView, QTabDialog, QListView, QDialog and QScrollView.

void QWidget::showEvent ( QShowEvent * ) [virtual protected]

This event handler can be reimplemented in a subclass to receive widget show events.

Non-spontaneous show events are sent to widgets right before they are shown. Spontaneous show events of toplevel widgets are delivered afterwards, naturally.

See also event() and QShowEvent.

Reimplemented in QTable, QProgressDialog, QTextBrowser, QHeader, QWorkspace, QListView, QListBox, QTabWidget and QTextView.

void QWidget::showFullScreen () [slot]

Shows the widget in full-screen mode.

Calling this function has no effect for other than top-level widgets.

To return from full-screen mode, call showNormal().

Full-screen mode works fine under Windows, but has certain problems under X. These problems are due to limitations of the ICCCM protocol that specifies the communication between X11 clients and the window manager. ICCCM simply does not know the concept of non-decorated full-screen windows. Therefore, the best we can do is to request a borderless window and place and resize it to fill the entire screen. Depending on the window manager, this may or may not work. The borderless window is requested using MOTIF hints, which are at least partially supported by virtually all modern window managers.

An alternative would be to bypass the window manager at all and to create a window with the WX11BypassWM flag. This has other severe problems, though, like totally broken keyboard focus and very strange effects on desktop changes or when the user raises other windows.

Future window managers that follow modern post-ICCCM specifications may support full-screen mode properly.

See also showNormal(), showMaximized(), show(), hide() and isVisible().

void QWidget::showMaximized () [virtual slot]

Shows the widget maximized.

Calling this function has no effect for other than top-level widgets.

On X11, this function may not work properly with certain window managers. See the Window Geometry documentation for details on why.

See also showNormal(), showMinimized(), show(), hide() and isVisible().

Examples: scribble/main.cpp helpviewer/main.cpp qwerty/main.cpp

void QWidget::showMinimized () [virtual slot]

Shows the widget minimized, as an icon.

Calling this function has no effect for other than top-level widgets.

See also showNormal(), showMaximized(), show(), hide(), isVisible() and isMinimized().

void QWidget::showNormal () [virtual slot]

Restores the widget after it has been maximized or minimized.

Calling this function has no effect for other than top-level widgets.

See also showMinimized(), showMaximized(), show(), hide() and isVisible().

QSize QWidget::size () const

Returns the size of the widget, excluding the window frame.

See also geometry(), width() and height().

QSize QWidget::sizeHint () const [virtual]

Returns a recommended size for the widget, or an invalid size if no size is recommended.

The default implementation returns an invalid size if there is no layout for this widget, the layout's preferred size otherwise.

See also QSize::isValid(), minimumSizeHint(), sizePolicy(), setMinimumSize() and updateGeometry().

Reimplemented in QIconView, QCheckBox, QProgressBar, QComboBox, QSizeGrip, QCanvasView, QFrame, QTable, QListView, QScrollBar, QSplitter, QTabBar, QWorkspace, QLCDNumber, QDial, QMainWindow, QListBox, QLabel, QPopupMenu, QScrollView, QSpinBox, QToolButton, QHBox, QLineEdit, QWidgetStack, QHeader, QDialog, QGrid, QPushButton, QTabWidget, QProgressDialog, QMultiLineEdit, QRadioButton, QMenuBar, QGroupBox and QSlider.

QSize QWidget::sizeIncrement () const

Returns the widget size increment.

See also setSizeIncrement(), minimumSize() and maximumSize().

QSizePolicy QWidget::sizePolicy () const [virtual]

Returns the default layout behaviour of this widget.

If there is a QLayout that manages this widget's children, the size policy specified by that layout is used. If there is no such QLayout, the result of this function is used.

See also setSizePolicy(), sizeHint(), QLayout, QSizePolicy and updateGeometry().

Reimplemented in QCheckBox, QTabBar, QRadioButton, QWorkspace, QMultiLineEdit, QLabel, QProgressBar, QScrollView, QIconView, QPushButton, QLineEdit, QSpinBox, QHeader, QFrame, QLCDNumber, QSizeGrip, QSplitter, QScrollBar, QTabWidget, QSlider and QToolButton.

void QWidget::stackUnder ( QWidget * w ) [slot]

Places the widget under w in the parent widget's stack.

To make this work, the widget itself and w have to be siblings.

See also raise() and lower().

QStyleQWidget::style () const

Returns the GUI style for this widget

See also QWidget::setStyle(), QApplication::setStyle() and QApplication::style().

void QWidget::styleChange ( QStyle & oldStyle ) [virtual protected]

This virtual function is called when the style of the widgets. changes.oldStyle is the previous GUI style; you can get the new style from style().

Reimplement this function if your widget needs to know when its GUI style changes. You will almost certainly need to update the widget using update().

The default implementation updates the widget including its geometry.

See also QApplication::setStyle(), style(), update() and updateGeometry().

Reimplemented in QSplitter, QSlider, QSpinBox, QTabWidget, QMainWindow, QComboBox, QScrollView, QProgressBar, QListView, QPopupMenu, QProgressDialog, QIconView, QScrollBar, QMenuBar, QTabBar, QTabDialog and QToolBar.

bool QWidget::testWFlags ( WFlags f ) const

Returns TRUE if any of the widget flags in f are set.

Widget flags are a combination of Qt::WidgetFlags.

See also getWFlags(), setWFlags() and clearWFlags().

QWidget * QWidget::topLevelWidget () const

Returns the top-level widget for this widget, i.e. the next ancestor widget that has a window-system frame (or at least may have one).

If the widget is a top-level, the widget itself is returned.

Typical usage is changing the window caption:

    aWidget->topLevelWidget()->setCaption( "New Caption" );

See also isTopLevel().

void QWidget::unsetCursor () [virtual]

Unset the cursor for this widget. The widget will use the cursor of its parent from now on.

This functions does nothing for top-level windows.

See also cursor(), setCursor() and QApplication::setOverrideCursor().

void QWidget::unsetFont ()

Unsets the font for this widget. The widget will use its natural default font from now on. This is either a special font for the widget class, the parent's font or - if this widget is a toplevel widget - the default application font.

See also setFont() and ownFont().

void QWidget::unsetPalette ()

Unsets the palette for this widget. The widget will use its natural default palette from now on.

See also setPalette() and ownPalette().

void QWidget::update () [slot]

Updates the widget unless updates are disabled or the widget is hidden.

Updating the widget will erase the widget contents and generate an appropriate paint event for the invalidated region. The paint event is processed after the program has returned to the main event loop. Calling update() many times in a row will generate a single paint event.

If the widgets sets the WRepaintNoErase flag, update() will not erase its contents.

See also repaint(), paintEvent(), setUpdatesEnabled(), erase() and setWFlags().

Examples: scrollview/scrollview.cpp grapher/grapher.cpp

void QWidget::update ( int x, int y, int w, int h ) [slot]

Updates a rectangle (x, y, w, h) inside the widget unless updates are disabled or the widget is hidden.

Updating the widget erases the widget area (x,y,w,h) and generate an appropriate paint event for the invalidated region. The paint event is processed after the program has returned to the main event loop. Calling update() many times in a row will generate a single paint event.

If w is negative, it is replaced with width() - x. If h is negative, it is replaced width height() - y.

If the widgets sets the WRepaintNoErase flag, update() will not erase its contents.

See also repaint(), paintEvent(), setUpdatesEnabled() and erase().

Examples: picture/picture.cpp drawlines/connect.cpp desktop/desktop.cpp drawdemo/drawdemo.cpp

void QWidget::update ( const QRect & r ) [slot]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QWidget::updateGeometry ()

Notifies the layout system that this widget has changed and may need to change geometry.

Call this function if the sizeHint() or sizePolicy() have changed.

For explicitly hidden widgets, updateGeometry() is a no-op. The layout system will be notified as soon as the widget is shown.

void QWidget::updateMask () [virtual protected]

This function can be reimplemented in a subclass to support transparent widgets. It is supposed to be called whenever a widget changes state in a way that the shape mask has to be recalculated.

See also setAutoMask(), updateMask(), setMask() and clearMask().

Reimplemented in QSlider, QPushButton, QFrame, QRadioButton, QTabWidget, QTabBar, QCheckBox, QGroupBox and QComboBox.

QRect QWidget::visibleRect () const

Returns the currently visible rectangle of the widget. This function is in particular useful to optimize immediate repainting of a widget. Typical usage is

  repaint( w->visibleRect() );

or

  repaint( w->visibleRect(), FALSE );

If nothing is visible, the rectangle returned is empty.

void QWidget::wheelEvent ( QWheelEvent * e ) [virtual protected]

This event handler can be reimplemented in a subclass to receive wheel events for the widget.

If you reimplement this handler, it is very important that you ignore() the event if you do not handle it, so that the widget's parent can interpret it.

The default implementation ignores the event.

See also QWheelEvent::ignore(), QWheelEvent::accept(), event() and QWheelEvent.

Reimplemented in QMultiLineEdit, QSpinBox, QScrollBar, QSlider, QScrollView and QDial.

int QWidget::width () const

Returns the width of the widget, excluding the window frame.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also geometry(), height() and size().

Examples: xform/xform.cpp menu/menu.cpp qmag/qmag.cpp grapher/grapher.cpp drawdemo/drawdemo.cpp

WId QWidget::winId () const

Returns the window system identifier of the widget.

Portable in principle, but if you use it you are probably about to do something non-portable. Be careful.

See also find().

int QWidget::x () const

Returns the x coordinate of the widget, relative to its parent widget and including the window frame.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also frameGeometry(), y() and pos().

int QWidget::y () const

Returns the y coordinate of the widget, relative to its parent widget and including the window frame.

See the Window Geometry documentation for an overview of geometry issues with top-level widgets.

See also frameGeometry(), x() and pos().

Examples: drawdemo/drawdemo.cpp

void QWidget::clearWState ( uint n ) [protected]

For internal use only.

QWExtra * QWidget::extraData () [protected]

For internal use only.

uint QWidget::getWState () const [protected]

For internal use only.

void QWidget::setCRect ( const QRect & r ) [virtual protected]

For internal use only.

void QWidget::setFRect ( const QRect & r ) [virtual protected]

For internal use only.

void QWidget::setWState ( uint n ) [virtual protected]

For internal use only.

bool QWidget::testWState ( uint n ) const

For internal use only.

QTLWExtra * QWidget::topData () [protected]

For internal use only.

QWidgetMapper * QWidget::wmapper () [static]

For internal use only.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.


Copyright © 2005 TrolltechTrademarks
Qt version 2.3.10