Qt logo

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, QDialog, QFrame, QGLWidget, QLineEdit, QMainWindow, QNPWidget, QScrollBar, QSemiModal, QSlider, QStatusBar, QTabBar, QToolBar, QWindow and QXtWidget.

List of all member functions.

Public Members

Public Slots

Static Public Members

Protected Members


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 without a parent, called a top-level widget, is a window with a frame and a title bar (though it is also possible to create top level widgets without such decoration). A widget with a parent is a child window in its parent. You usually cannot distinguish a child widget from its parent visually.

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 (except resizeEvent() for custom layout management).

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 every other event to one of the more specialized handlers above.

When writing a widget, there are a few more things to look out for. In the constructor, be sure to set up your member variables early on, before there's any chance that you might receive an event.

It is often a good idea to reimplement sizeHint(), so users of your class can set up layout management more easily. If you do, consider offering size management using autoMinimumSize() too.

If your widget is a top-level window, setCaption() and setIcon() set the title bar and icon respectively.

See also: QEvent, QPainter, QGridLayout and QBoxLayout.

Examples: tictac/tictac.cpp life/life.cpp dclock/dclock.cpp forever/forever.cpp desktop/desktop.cpp connect/connect.cpp tooltip/tooltip.cpp hello/hello.cpp xform/xform.cpp aclock/aclock.cpp menu/menu.cpp pref/pref.cpp progress/progress.cpp layout/layout.cpp qmag/qmag.cpp showimg/showimg.cpp biff/biff.cpp widgets/widgets.cpp


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 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 these flags:

Note that X11 does not necessarily support all style flag combinations. X11 window managers live their own lives and can only take hints. Win32 supports all style flags.

Example:

    QLabel *toolTip = new QLabel( 0, "myToolTip",
                                  WStyle_Customize | WStyle_NoBorder |
                                  WStyle_Tool );

The widget flags are defined in qwindowdefs.h (which is included by qwidget.h).

QWidget::~QWidget ()

Destroys 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: movies/main.cpp

Reimplemented in QMessageBox.

const QColor & QWidget::backgroundColor () const

Returns the background color of this widget.

The background color is independent of the color group.

Setting a new palette overwrites the background color.

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

Examples: grapher/grapher.cpp xform/xform.cpp widgets/widgets.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 update the widget using either repaint(TRUE) or update().

The default implementation calls update().

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

const QPixmap * QWidget::backgroundPixmap () const

Returns the background pixmap, or null if no background pixmap has not been set. If the widget has been made empty, this function will return a pixmap which isNull() rather than 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 update the widget using either repaint(TRUE) or update().

The default implementation calls update().

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

const char * QWidget::caption () const

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

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

QRect QWidget::childrenRect () const

Returns the bounding rectangle of the widget's children.

Examples: widgets/widgets.cpp

void QWidget::clearFocus ()

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 loose 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]

For internal use only.

bool QWidget::close ( bool forceKill=FALSE ) [virtual]

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.

If forceKill is TRUE, the widget is deleted whether it accepts the close event or not.

The application is terminated when the main widget is closed.

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

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

Examples: application/application.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 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 focus returns the QPalette::active() color group and a normal widget returns the QPalette::normal() color group.

See also: palette() and setPalette().

Examples: life/life.cpp

void QWidget::create ( WId window ) [protected]

For internal use only.

void QWidget::create ( WId window, bool initializeWindow, bool destroyOldWindow ) [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.

See also: setCursor().

void QWidget::destroy ( bool destroyWindow, bool destroySubWindows ) [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::drawText ( int x, int y, const char * 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 char * 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::enabledChange ( bool oldEnabled ) [virtual protected]

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

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 either repaint(TRUE) or update().

The default implementation calls repaint(TRUE).

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

Reimplemented in QSpinBox and QButton.

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.

The default implementation does nothing.

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

Reimplemented in QToolButton.

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().

Examples: connect/connect.cpp

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.

QWExtra * QWidget::extraData () [protected]

For internal use only.

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 id().

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 must accept focus initially in order to receive focus events.

The default implementation calls repaint() since the widget's color group changes from normal to active. You may want to call repaint(FALSE) to reduce flicker in any reimplementation.

As a special case to support applications not utilizing focus, Top-level widgets that have NoFocus policy will receive focus events and gain keyboard events, but the repaint is not done by default.

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

Reimplemented in QSlider, QPushButton, QListBox, QButton, QMultiLineEdit, QListView, QLineEdit and QComboBox.

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.

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 must accept focus initially in order to receive focus events.

The default implementation calls repaint() since the widget's color group changes from active to normal. You may want to call repaint(FALSE) to reduce flicker in any reimplementation.

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

Reimplemented in QListBox, QButton, QMultiLineEdit, QListView and QLineEdit.

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.

const QFont & QWidget::font () const

Returns the font currently set for the widget.

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

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

Examples: grapher/grapher.cpp hello/hello.cpp xform/xform.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 either repaint(TRUE) or update().

The default implementation calls update().

See also: setFont(), font(), repaint() and update().

Reimplemented in QSpinBox and QMenuBar.

QFontInfo QWidget::fontInfo () const

Returns the font info for the widget.

The font info object is automatically updated if somebody sets a new widget font. We have decided to change this policy in Qt 2.0: setting a new font for a widget should not affect existing QFontInfo objects.

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

Examples: xform/xform.cpp

QFontMetrics QWidget::fontMetrics () const

Returns the font metrics for the widget.

The font metrics object is automatically updated if somebody sets a new widget font. We have decided to change this policy in Qt 2.0: setting a new font for a widget should not affect existing QFontMetrics objects.

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

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

QWidget::PropagationMode QWidget::fontPropagation() const

Returns the font propagation mode of this widget. The default font propagation mode is NoChildren, but you can set it to SameFont or AllChildren.

See also: setFontPropagation().

const QColor & QWidget::foregroundColor () const

Returns the foreground color of this widget.

The foreground color equals colorGroup().foreground().

See also: backgroundColor() and colorGroup().

Examples: aclock/aclock.cpp

const QRect & QWidget::frameGeometry () const

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

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

const QRect & QWidget::geometry () const

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

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

Examples: qmag/qmag.cpp

WFlags QWidget::getWFlags () const [protected]

For internal use only.

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.

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

Examples: qmag/qmag.cpp

void QWidget::grabMouse ( const QCursor & cursor )

Grabs the mouse intput 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().

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 also: geometry(), width() and size().

Examples: grapher/grapher.cpp tooltip/tooltip.cpp drawdemo/drawdemo.cpp xform/xform.cpp aclock/aclock.cpp pref/pref.cpp qmag/qmag.cpp showimg/showimg.cpp

void QWidget::hide () [virtual slot]

Hides the widget.

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

See also: show(), iconify() and isVisible().

Examples: xform/xform.cpp progress/progress.cpp

Reimplemented in QPopupMenu and QMenuBar.

const QPixmap * QWidget::icon () const

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

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

const char * QWidget::iconText () const

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

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

void QWidget::iconify () [slot]

Iconifies the widget.

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

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

bool QWidget::isActiveWindow () const

Returns TRUE if the top-level widget containing this widget is the active window.

See also: setActiveWindow() and topLevelWidget().

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 and every parent up to but excluding ancestor is enabled, otherwise returns FALSE.

See also: setEnabled() and isEnabled().

bool QWidget::isEnabledToTLW () const

Returns TRUE if this widget and every parent up to the top level widget is enabled, otherwise returns FALSE.

This is equivalent to isEnabledTo(0).

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::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. Modal dialog widgets are the only top-level widgets that can have parent widgets; all other top-level widgets have null parents. 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 set to visible status, or else FALSE. Calling show() sets the widget to visible status; calling hide() sets it to hidden status. Iconified top-level widgets also have hidden status.

If a widget is set to visible status, but its parent widget is set to hidden status, this function returns TRUE. isVisibleToTLW() looks at the visibility status of the parent widgets up to the top level widget.

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

See also: show(), hide() and isVisibleToTLW().

bool QWidget::isVisibleTo ( QWidget * ancestor ) const

Returns TRUE if this widget and every parent up to but excluding ancestor is visible, otherwise returns FALSE.

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

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

bool QWidget::isVisibleToTLW () const

Returns TRUE if this widget and every parent up to the top level widget is visible, otherwise returns FALSE.

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

This is equivalent to isVisibleTo(0).

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 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 press if you do not understand it, so that the widget's parent can interpret it.

The default implementation ignores the event.

As a special case to support applications not utilizing focus, Top-level widgets that have NoFocus policy will receive keyboard events.

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

Reimplemented in QSlider, QListBox, QButton, QTabBar, QMultiLineEdit, QListView, QPopupMenu, QMessageBox, QScrollBar, QLineEdit, QDialog, QRadioButton, QFileDialog, QMenuBar and QComboBox.

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.

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().

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.

The default implementation does nothing.

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

Reimplemented in QToolButton, QMultiLineEdit, QXtWidget, 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().

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

Translates the global screen coordinate pos to widget coordinates.

See also: mapToGlobal().

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

Translates the parent widget coordinate pos to widget coordinates.

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

See also: mapToParent().

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().

QPoint QWidget::mapToParent ( const QPoint & p ) 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().

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: setMaximumSize(), minimumSize() and sizeIncrement().

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

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

Use the QPaintDeviceMetrics class instead.

Reimplemented from QPaintDevice.

QSize QWidget::minimumSize () const

Returns the minimum widget size.

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

See also: setMinimumSize(), maximumSize() and sizeIncrement().

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 QListBox, QMultiLineEdit, QListView, QLineEdit and QComboBox.

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.

The default implementation does nothing.

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

Reimplemented in QSlider, QListBox, QButton, QMultiLineEdit, QListView, QPopupMenu, QScrollBar, QLineEdit, QMenuBar and QComboBox.

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

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

The default implementation does nothing.

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.

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

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

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

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

The default implementation does nothing.

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

Reimplemented in QSlider, QListBox, QTabBar, QButton, QMultiLineEdit, QListView, QPopupMenu, QScrollBar, QLineEdit, QRadioButton, QMenuBar and QComboBox.

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

Moves the widget to the position (x,y) relative to the parent widget.

A move event is generated immediately if the widget is visible. If the widget is invisible, the move event is generated when show() is called.

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 also: pos(), resize(), setGeometry() and moveEvent().

Examples: xform/xform.cpp

Reimplemented in QSemiModal and QDialog.

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: drawdemo/drawdemo.cpp xform/xform.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().

The default implementation does nothing.

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

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

This event handler can be reimplemented in a subclass to receive widget paint events. Actually, it more or less must be reimplemented.

The default implementation does nothing.

When the paint event occurs, the update rectangle QPaintEvent::rect() normally has been cleared to the background color or pixmap. An exception is repaint() with erase=FALSE.

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

Pixmaps can also be used to implement flicker-free update.

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

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

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

const QPalette & QWidget::palette () const

Returns the widget 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 update the widget using either repaint(TRUE) or update().

The default implementation calls update().

See also: setPalette(), palette(), repaint() and update().

Reimplemented in QSpinBox.

QWidget::PropagationMode QWidget::palettePropagation() const

Returns the palette propagation mode of this widget. The default palette propagation mode is NoChildren, but you can set it to SamePalette or AllChildren.

See also: setPalettePropagation().

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.

QPoint QWidget::pos () const

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

See also: 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().

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

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 recreated.

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, recreate() calls clearFocus() for that widget.

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

See also: getWFlags().

QRect QWidget::rect () const

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

See also: size().

Examples: grapher/grapher.cpp desktop/desktop.cpp picture/picture.cpp menu/menu.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 ( 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.

Doing a repaint() usually is faster than doing an update(), but 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: forever/forever.cpp tooltip/tooltip.cpp hello/hello.cpp qmag/qmag.cpp showimg/showimg.cpp biff/biff.cpp

void QWidget::repaint ( 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.

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.

Examples: life/life.cpp forever/forever.cpp pref/pref.cpp

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

Resizes the widget to size w by h pixels.

A resize event is generated immediately if the widget is visible. If the widget is invisible, the resize event is generated when show() is called.

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: tictac/tictac.cpp hello/hello.cpp xform/xform.cpp layout/layout.cpp qmag/qmag.cpp showimg/showimg.cpp biff/biff.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 table/table.cpp life/life.cpp drawdemo/drawdemo.cpp xform/xform.cpp application/application.cpp pref/pref.cpp qmag/qmag.cpp mainlyXt/editor.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().

The default implementation does nothing.

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

Reimplemented in QGLWidget, QSlider, QSpinBox, QListBox, QHeader, QMultiLineEdit, QLCDNumber, QTableView, QListView, QMessageBox, QScrollBar, QLineEdit, QFrame, QProgressDialog, QScrollView, QFileDialog, QMenuBar, QTabDialog and QComboBox.

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

Scrolls the contents of the widget dx pixels rightwards and dy pixels downwards. If dx/dy is negative, the scroll direction is leftwards/upwards. Child widgets are moved accordingly.

The areas of the widget that are exposed will be erased and paint events may be generated immediately, or after some further event processing.

Warning: If you call scroll() in a function which may itself be called from the moveEvent() or paintEvent() of a direct child of the widget being scrolled, you may see infinite recursion.

See also: erase() and bitBlt().

void QWidget::setAcceptDrops ( bool on )

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

In Qt 1.x, drop event handlers are in QDropSite.

See also: acceptDrops().

void QWidget::setActiveWindow ()

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

An active window is a 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.

See also: isActiveWindow() and topLevelWidget().

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

This function is deprecated. Use setBackgroundMode() or setPalette(), as they ensure the appropriate clearing color is used when the widget is in the Active, Normal, or Disabled state.

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) ) );

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

Examples: tictac/tictac.cpp desktop/desktop.cpp connect/connect.cpp drawdemo/drawdemo.cpp xform/xform.cpp layout/layout.cpp widgets/widgets.cpp

Reimplemented in QTableView and QComboBox.

void QWidget::setBackgroundMode ( BackgroundMode m )

Tells the window system which color to clear this widget to when sending a paint event.

In other words, this color is the color of the widget when paintEvent() is called. To minimize flicker, this should be the most common color in the widget.

The following values are valid:

If setBackgroundPixmap() or setBackgroundColor() is called, the mode will be one of:

These values may not be used as parameters to setBackgroundMode().

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 );

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) ) );

You can also use QApplication::setPalette() if you want to change the color scheme of your entire application, or of all new widgets.

Examples: table/table.cpp widgets/widgets.cpp

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

Sets the background pixmap of the widget to pixmap.

The background pixmap is tiled. Some widgets (e.g. QLineEdit) do not work well with a background pixmap.

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

Examples: desktop/desktop.cpp

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

For internal use only.

void QWidget::setCaption ( const char * caption ) [slot]

Sets the window caption (title).

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

Examples: drawdemo/drawdemo.cpp movies/main.cpp application/application.cpp pref/pref.cpp progress/progress.cpp showimg/showimg.cpp widgets/widgets.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() and QApplication::setOverrideCursor().

Examples: cursor/cursor.cpp

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.

See also: isEnabled(), QKeyEvent and QMouseEvent.

Reimplemented in QLineEdit and QComboBox.

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

For internal use only.

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: widgets/widgets.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.

Examples: pref/pref.cpp widgets/widgets.cpp

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 ()

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 loose 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. However, QWidget::focusWidget() (which determines where Tab/shift-Tab) moves from) is changed only if the widget accepts focus. This can be used to implement "hidden focus"; see focusNextPrevChild() for details.

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().

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).

The policy can be:

As a special case to support applications not utilizing focus, Top-level widgets that have NoFocus policy will receive focus events and gain keyboard events.

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

Examples: table/table.cpp widgets/widgets.cpp

void QWidget::setFocusProxy ( QWidget * w )

Sets this widget's focus proxy to w.

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.

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

Sets the font for the widget.

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 );

If fontPropagation() is AllChildren or SameFont, setFont() calls setFont() for children of the object, or those with whom the object shares the font, respectively. The default for QWidget is NoChildren, so setFont() will not change the children's fonts.

See also: font(), fontChange(), fontInfo(), fontMetrics() and setFontPropagation().

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

Reimplemented in QMultiLineEdit, QPopupMenu, QListView, QLineEdit, QTabDialog, QComboBox and QListBox.

void QWidget::setFontPropagation ( PropagationMode m )

Sets the font propagation mode to m.

if m is NoChildren (the default), setFont() does not change any children's fonts. If it is SameFont, setFont() changes the font of the children that have the exact same font as this widget (see QFont::isCopyOf() for details). If it is AllChildren, setFont() changes the font of all children.

See also: fontPropagation(), setFont() and setPalettePropagation().

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.

A resize event and a move event are generated immediately if the widget is visible. If the widget is invisible, the events are generated when show() is called.

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().

Examples: tictac/tictac.cpp mainlyQt/editor.cpp drawdemo/drawdemo.cpp xform/xform.cpp cursor/cursor.cpp qmag/qmag.cpp

Reimplemented in QPushButton, QSemiModal, QXtWidget and QDialog.

void QWidget::setGeometry ( const QRect & ) [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::setIcon ( const QPixmap & pixmap ) [slot]

Sets the window icon pixmap.

See also: icon(), setIconText() and setCaption().

void QWidget::setIconText ( const char * iconText ) [slot]

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

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

void QWidget::setMask ( QBitmap bitmap )

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 )

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.

void QWidget::setMaximumSize ( int maxw, int maxh )

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().

Examples: life/life.cpp biff/biff.cpp

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::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.

Examples: layout/layout.cpp widgets/widgets.cpp

void QWidget::setMinimumSize ( int minw, int minh )

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.

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

Examples: life/life.cpp tooltip/tooltip.cpp menu/menu.cpp pref/pref.cpp layout/layout.cpp qmag/qmag.cpp biff/biff.cpp widgets/widgets.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 ) [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: qmag/qmag.cpp showimg/showimg.cpp

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

Sets the widget palette to p. The widget background color is set to colorGroup().background().

If palettePropagation() is AllChildren or SamePalette, setPalette() calls setPalette() for children of the object, or those with whom the object shares the palette, respectively. The default for QWidget is NoChildren, so setPalette() will not change the children's palettes.

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

Reimplemented in QTableView, QListView, QScrollBar, QLineEdit, QComboBox and QSlider.

void QWidget::setPalettePropagation ( PropagationMode m )

Sets the palette propagation mode to m.

if m is NoChildren (the default), setPalette() does not change any children's palettes. If it is SamePalette, setPalette() changes the palette of the children that have the exact same palette as this widget (see QPalette::isCopyOf() for details). If it is AllChildren, setPalette() changes the palette of all children.

See also: palettePropagation(), setPalette() and setFontPropagation().

void QWidget::setSizeGrip ( bool sizegrip ) [protected]

Informs the underlying window system that this widget is a size grip (if sizegrip is TRUE). An example is the nifty decoration in the bottom right corner of a QStatusBar.

This function does yet nothing under Windows. Under X11, the window manager has to support the QT_SIZEGRIP protocol.

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

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.

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.

Examples: life/life.cpp

void QWidget::setStyle ( GUIStyle style ) [virtual]

Sets the GUI style for this widget. The valid values are listed in qwindowdefs.h.

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

Examples: grapher/grapher.cpp

Reimplemented in QListView, QMessageBox and QComboBox.

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().

void QWidget::setUpdatesEnabled ( bool enable ) [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 as 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().

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

For internal use only.

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.

See also: hide(), iconify() and isVisible().

Examples: forever/forever.cpp connect/connect.cpp mainlyQt/editor.cpp drawdemo/drawdemo.cpp movies/main.cpp picture/picture.cpp xform/xform.cpp menu/menu.cpp pref/pref.cpp progress/progress.cpp cursor/cursor.cpp layout/layout.cpp qmag/qmag.cpp showimg/showimg.cpp widgets/widgets.cpp

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

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.

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

Examples: widgets/widgets.cpp

Reimplemented in QToolButton, QPushButton, QSpinBox, QListBox, QTabBar, QHeader, QLCDNumber, QListView, QScrollBar, QLineEdit, QCheckBox, QProgressDialog, QRadioButton, QLabel, QComboBox, QSlider and QProgressBar.

QSize QWidget::sizeIncrement () const

Returns the widget size increment.

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

GUIStyle QWidget::style () const

Returns the GUI style for this widget.

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

void QWidget::styleChange ( GUIStyle oldStyle ) [virtual protected]

This virtual function is called from setStyle(). oldStyle is the previous 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 either repaint(TRUE) or update().

The default implementation calls update().

See also: setStyle(), style(), repaint() and update().

Reimplemented in QSpinBox, QProgressDialog and QTabDialog.

bool QWidget::testWFlags ( WFlags n ) const

Returns non-zero if any of the widget flags in n are set. The widget flags are listed in qwindowdefs.h, and are strictly for internal use.

QWidget * QWidget::topLevelWidget () const

Returns the top-level widget for this widget.

A top-level widget is an overlapping widget. It usually has no parent. Modal dialog widgets are the only top-level widgets that can have parent widgets.

See also: isTopLevel().

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 a paint event from the window system. The paint event is processed after the program has returned to the main event loop.

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

Examples: desktop/desktop.cpp connect/connect.cpp picture/picture.cpp aclock/aclock.cpp showimg/showimg.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), which in turn generates a paint event from the window system. The paint event is processed after the program has returned to the main event loop.

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

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

Examples: grapher/grapher.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.

int QWidget::width () const

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

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

Examples: grapher/grapher.cpp tooltip/tooltip.cpp drawdemo/drawdemo.cpp xform/xform.cpp aclock/aclock.cpp menu/menu.cpp pref/pref.cpp qmag/qmag.cpp showimg/showimg.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().

QWidgetMapper * QWidget::wmapper () [static]

For internal use only.

int QWidget::x () const

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

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 also: frameGeometry(), x() and pos().

Examples: drawdemo/drawdemo.cpp


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


This file is part of the Qt toolkit, copyright © 1995-98 Troll Tech, all rights reserved.

It was generated from the following files:


Copyright © 1998 Troll TechTrademarks
Qt version 1.42