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 QAxWidget, QButton, QFrame, QDialog, QComboBox, QDataBrowser, QDataView, QDateTimeEditBase, QDateTimeEdit, QDesktopWidget, QDial, QDockArea, QGLWidget, QHeader, QMainWindow, QMotifWidget, QNPWidget, QScrollBar, QSizeGrip, QSlider, QSpinBox, QSplashScreen, QStatusBar, QTabBar, QTabWidget, QWorkspace, and QXtWidget.
List of all member functions.
Public Members
- explicit QWidget ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )
- ~QWidget ()
- WId winId () const
- QStyle & style () const
- void setStyle ( QStyle * style )
- QStyle * setStyle ( const QString & style )
- bool isTopLevel () const
- bool isDialog () const
- bool isPopup () const
- bool isDesktop () const
- bool isModal () const
- bool isEnabled () const
- bool isEnabledTo ( QWidget * ancestor ) const
- bool isEnabledToTLW () const (obsolete)
- QRect frameGeometry () const
- const QRect & geometry () const
- int x () const
- int y () const
- QPoint pos () const
- QSize frameSize () const
- QSize size () const
- int width () const
- int height () const
- QRect rect () const
- QRect childrenRect () const
- QRegion childrenRegion () const
- QSize minimumSize () const
- QSize maximumSize () const
- int minimumWidth () const
- int minimumHeight () const
- int maximumWidth () const
- int maximumHeight () const
- void setMinimumSize ( const QSize & )
- virtual void setMinimumSize ( int minw, int minh )
- void setMaximumSize ( const QSize & )
- virtual void setMaximumSize ( int maxw, int maxh )
- void setMinimumWidth ( int minw )
- void setMinimumHeight ( int minh )
- void setMaximumWidth ( int maxw )
- void setMaximumHeight ( int maxh )
- QSize sizeIncrement () const
- void setSizeIncrement ( const QSize & )
- virtual void setSizeIncrement ( int w, int h )
- QSize baseSize () const
- void setBaseSize ( const QSize & )
- void setBaseSize ( int basew, int baseh )
- void setFixedSize ( const QSize & s )
- void setFixedSize ( int w, int h )
- void setFixedWidth ( int w )
- void setFixedHeight ( int h )
- QPoint mapToGlobal ( const QPoint & pos ) const
- QPoint mapFromGlobal ( const QPoint & pos ) const
- QPoint mapToParent ( const QPoint & pos ) const
- QPoint mapFromParent ( const QPoint & pos ) const
- QPoint mapTo ( QWidget * parent, const QPoint & pos ) const
- QPoint mapFrom ( QWidget * parent, const QPoint & pos ) const
- QWidget * topLevelWidget () const
- BackgroundMode backgroundMode () const
- virtual void setBackgroundMode ( BackgroundMode )
- void setBackgroundMode ( BackgroundMode m, BackgroundMode visual )
- const QColor & foregroundColor () const
- const QColor & eraseColor () const
- virtual void setEraseColor ( const QColor & color )
- const QPixmap * erasePixmap () const
- virtual void setErasePixmap ( const QPixmap & pixmap )
- const QColorGroup & colorGroup () const
- const QPalette & palette () const
- bool ownPalette () const
- virtual void setPalette ( const QPalette & )
- void unsetPalette ()
- const QColor & paletteForegroundColor () const
- void setPaletteForegroundColor ( const QColor & )
- const QColor & paletteBackgroundColor () const
- virtual void setPaletteBackgroundColor ( const QColor & )
- const QPixmap * paletteBackgroundPixmap () const
- virtual void setPaletteBackgroundPixmap ( const QPixmap & )
- const QBrush & backgroundBrush () const
- QFont font () const
- bool ownFont () const
- virtual void setFont ( const QFont & )
- void unsetFont ()
- QFontMetrics fontMetrics () const
- QFontInfo fontInfo () const
- const QCursor & cursor () const
- bool ownCursor () const
- virtual void setCursor ( const QCursor & )
- virtual void unsetCursor ()
- QString caption () const
- const QPixmap * icon () const
- QString iconText () const
- bool hasMouseTracking () const
- bool hasMouse () const
- virtual void setMask ( const QBitmap & bitmap )
- virtual void setMask ( const QRegion & region )
- void clearMask ()
- const QColor & backgroundColor () const (obsolete)
- virtual void setBackgroundColor ( const QColor & c ) (obsolete)
- const QPixmap * backgroundPixmap () const (obsolete)
- virtual void setBackgroundPixmap ( const QPixmap & pm ) (obsolete)
- enum FocusPolicy { NoFocus = 0, TabFocus = 0x1, ClickFocus = 0x2, StrongFocus = TabFocus | ClickFocus | 0x8, WheelFocus = StrongFocus | 0x4 }
- bool isActiveWindow () const
- virtual void setActiveWindow ()
- bool isFocusEnabled () const
- FocusPolicy focusPolicy () const
- virtual void setFocusPolicy ( FocusPolicy )
- bool hasFocus () const
- virtual void setFocusProxy ( QWidget * w )
- QWidget * focusProxy () const
- void setInputMethodEnabled ( bool b )
- bool isInputMethodEnabled () const
- void grabMouse ()
- void grabMouse ( const QCursor & cursor )
- void releaseMouse ()
- void grabKeyboard ()
- void releaseKeyboard ()
- bool isUpdatesEnabled () const
- virtual bool close ( bool alsoDelete )
- bool isVisible () const
- bool isVisibleTo ( QWidget * ancestor ) const
- bool isVisibleToTLW () const (obsolete)
- QRect visibleRect () const (obsolete)
- bool isHidden () const
- bool isShown () const
- bool isMinimized () const
- bool isMaximized () const
- bool isFullScreen () const
- uint windowState () const
- void setWindowState ( uint windowState )
- virtual QSize sizeHint () const
- virtual QSize minimumSizeHint () const
- virtual QSizePolicy sizePolicy () const
- virtual void setSizePolicy ( QSizePolicy )
- void setSizePolicy ( QSizePolicy::SizeType hor, QSizePolicy::SizeType ver, bool hfw = FALSE )
- virtual int heightForWidth ( int w ) const
- QRegion clipRegion () const
- QLayout * layout () const
- void updateGeometry ()
- virtual void reparent ( QWidget * parent, WFlags f, const QPoint & p, bool showIt = FALSE )
- void reparent ( QWidget * parent, const QPoint & p, bool showIt = FALSE )
- void recreate ( QWidget * parent, WFlags f, const QPoint & p, bool showIt = FALSE ) (obsolete)
- void erase ()
- void erase ( int x, int y, int w, int h )
- void erase ( const QRect & r )
- void erase ( const QRegion & reg )
- void scroll ( int dx, int dy )
- void scroll ( int dx, int dy, const QRect & r )
- void drawText ( int x, int y, const QString & str )
- void drawText ( const QPoint & pos, const QString & str )
- QWidget * focusWidget () const
- QRect microFocusHint () const
- bool acceptDrops () const
- virtual void setAcceptDrops ( bool on )
- virtual void setAutoMask ( bool )
- bool autoMask () const
- enum BackgroundOrigin { WidgetOrigin, ParentOrigin, WindowOrigin, AncestorOrigin }
- virtual void setBackgroundOrigin ( BackgroundOrigin )
- BackgroundOrigin backgroundOrigin () const
- virtual bool customWhatsThis () const
- QWidget * parentWidget ( bool sameWindow = FALSE ) const
- WFlags testWFlags ( WFlags f ) const
- QWidget * childAt ( int x, int y, bool includeThis = FALSE ) const
- QWidget * childAt ( const QPoint & p, bool includeThis = FALSE ) const
- void setWindowOpacity ( double level )
- double windowOpacity () const
- void setPalette ( const QPalette & p, bool ) (obsolete)
- void setFont ( const QFont & f, bool ) (obsolete)
Public Slots
- virtual void setEnabled ( bool )
- void setDisabled ( bool disable )
- virtual void setCaption ( const QString & )
- virtual void setIcon ( const QPixmap & )
- virtual void setIconText ( const QString & )
- virtual void setMouseTracking ( bool enable )
- virtual void setFocus ()
- void clearFocus ()
- virtual void setUpdatesEnabled ( bool enable )
- void update ()
- void update ( int x, int y, int w, int h )
- void update ( const QRect & r )
- void repaint ()
- void repaint ( bool erase )
- void repaint ( int x, int y, int w, int h, bool erase = TRUE )
- void repaint ( const QRect & r, bool erase = TRUE )
- void repaint ( const QRegion & reg, bool erase = TRUE )
- virtual void show ()
- virtual void hide ()
- void setShown ( bool show )
- void setHidden ( bool hide )
- void iconify () (obsolete)
- virtual void showMinimized ()
- virtual void showMaximized ()
- void showFullScreen ()
- virtual void showNormal ()
- virtual void polish ()
- void constPolish () const
- bool close ()
- void raise ()
- void lower ()
- void stackUnder ( QWidget * w )
- virtual void move ( int x, int y )
- void move ( const QPoint & )
- virtual void resize ( int w, int h )
- void resize ( const QSize & )
- virtual void setGeometry ( int x, int y, int w, int h )
- virtual void setGeometry ( const QRect & )
- virtual void adjustSize ()
Static Public Members
Properties
- bool acceptDrops - whether drop events are enabled for this widget
- bool autoMask - whether the auto mask feature is enabled for the widget
- QBrush backgroundBrush - the widget's background brush (read only)
- BackgroundMode backgroundMode - the color role used for painting the background of the widget
- BackgroundOrigin backgroundOrigin - the origin of the widget's background
- QSize baseSize - the base size of the widget
- QString caption - the window caption (title)
- QRect childrenRect - the bounding rectangle of the widget's children (read only)
- QRegion childrenRegion - the combined region occupied by the widget's children (read only)
- QColorGroup colorGroup - the current color group of the widget palette (read only)
- QCursor cursor - the cursor shape for this widget
- bool customWhatsThis - whether the widget wants to handle What's This help manually (read only)
- bool enabled - whether the widget is enabled
- bool focus - whether this widget (or its focus proxy) has the keyboard input focus (read only)
- bool focusEnabled - whether the widget accepts keyboard focus (read only)
- FocusPolicy focusPolicy - the way the widget accepts keyboard focus
- QFont font - the font currently set for the widget
- QRect frameGeometry - geometry of the widget relative to its parent including any window frame (read only)
- QSize frameSize - the size of the widget including any window frame (read only)
- bool fullScreen - whether the widget is full screen (read only)
- QRect geometry - the geometry of the widget relative to its parent and excluding the window frame
- int height - the height of the widget excluding any window frame (read only)
- bool hidden - whether the widget is explicitly hidden
- QPixmap icon - the widget's icon
- QString iconText - the widget's icon text
- bool inputMethodEnabled - enables or disables the use of input methods for this widget
- bool isActiveWindow - whether this widget is the active window (read only)
- bool isDesktop - whether the widget is a desktop widget, i.e. represents the desktop (read only)
- bool isDialog - whether the widget is a dialog widget (read only)
- bool isModal - whether the widget is a modal widget (read only)
- bool isPopup - whether the widget is a popup widget (read only)
- bool isTopLevel - whether the widget is a top-level widget (read only)
- bool maximized - whether this widget is maximized (read only)
- int maximumHeight - the widget's maximum height
- QSize maximumSize - the widget's maximum size
- int maximumWidth - the widget's maximum width
- QRect microFocusHint - the currently set micro focus hint for this widget (read only)
- bool minimized - whether this widget is minimized (iconified) (read only)
- int minimumHeight - the widget's minimum height
- QSize minimumSize - the widget's minimum size
- QSize minimumSizeHint - the recommended minimum size for the widget (read only)
- int minimumWidth - the widget's minimum width
- bool mouseTracking - whether mouse tracking is enabled for the widget
- bool ownCursor - whether the widget uses its own cursor (read only)
- bool ownFont - whether the widget uses its own font (read only)
- bool ownPalette - whether the widget uses its own palette (read only)
- QPalette palette - the widget's palette
- QColor paletteBackgroundColor - the background color of the widget
- QPixmap paletteBackgroundPixmap - the background pixmap of the widget
- QColor paletteForegroundColor - the foreground color of the widget
- QPoint pos - the position of the widget within its parent widget
- QRect rect - the internal geometry of the widget excluding any window frame (read only)
- bool shown - whether the widget is shown
- QSize size - the size of the widget excluding any window frame
- QSize sizeHint - the recommended size for the widget (read only)
- QSize sizeIncrement - the size increment of the widget
- QSizePolicy sizePolicy - the default layout behavior of the widget
- bool underMouse - whether the widget is under the mouse cursor (read only)
- bool updatesEnabled - whether updates are enabled
- bool visible - whether the widget is visible (read only)
- QRect visibleRect - the visible rectangle (read only) (obsolete)
- int width - the width of the widget excluding any window frame (read only)
- double windowOpacity - the level of opacity for the window
- int x - the x coordinate of the widget relative to its parent including any window frame (read only)
- int y - the y coordinate of the widget relative to its parent and including any window frame (read only)
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 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 (although it is also possible to create
top-level widgets without such decoration if suitable widget flags
are used). 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.
Non-top-level widgets are child widgets. These are child windows
in their parent widgets. You cannot usually distinguish a child
widget from its parent visually. Most other widgets in Qt are
useful only as child widgets. (It is possible to make, say, a
button into a top-level widget, but most people prefer to put
their buttons inside other widgets, e.g. QDialog.)
If you want to use a QWidget to hold child widgets you will
probably want to add a layout to the parent QWidget. (See Layouts.)
QWidget has many member functions, but some of them have little
direct functionality: for example, QWidget has a font property,
but never uses this itself. There are many subclasses which
provide real functionality, such as QPushButton, QListBox and
QTabDialog, etc.
Groups of functions:
| Context | Functions
|
| Window functions |
show(),
hide(),
raise(),
lower(),
close().
|
| Top level windows |
caption(),
setCaption(),
icon(),
setIcon(),
iconText(),
setIconText(),
isActiveWindow(),
setActiveWindow(),
showMinimized().
showMaximized(),
showFullScreen(),
showNormal().
|
| Window contents |
update(),
repaint(),
erase(),
scroll(),
updateMask().
|
| Geometry |
pos(),
size(),
rect(),
x(),
y(),
width(),
height(),
sizePolicy(),
setSizePolicy(),
sizeHint(),
updateGeometry(),
layout(),
move(),
resize(),
setGeometry(),
frameGeometry(),
geometry(),
childrenRect(),
adjustSize(),
mapFromGlobal(),
mapFromParent()
mapToGlobal(),
mapToParent(),
maximumSize(),
minimumSize(),
sizeIncrement(),
setMaximumSize(),
setMinimumSize(),
setSizeIncrement(),
setBaseSize(),
setFixedSize()
|
| Mode |
isVisible(),
isVisibleTo(),
isMinimized(),
isDesktop(),
isEnabled(),
isEnabledTo(),
isModal(),
isPopup(),
isTopLevel(),
setEnabled(),
hasMouseTracking(),
setMouseTracking(),
isUpdatesEnabled(),
setUpdatesEnabled(),
clipRegion().
|
| Look and feel |
style(),
setStyle(),
cursor(),
setCursor()
font(),
setFont(),
palette(),
setPalette(),
backgroundMode(),
setBackgroundMode(),
colorGroup(),
fontMetrics(),
fontInfo().
|
Keyboard focus functions |
isFocusEnabled(),
setFocusPolicy(),
focusPolicy(),
hasFocus(),
setFocus(),
clearFocus(),
setTabOrder(),
setFocusProxy().
|
Mouse and keyboard grabbing |
grabMouse(),
releaseMouse(),
grabKeyboard(),
releaseKeyboard(),
mouseGrabber(),
keyboardGrabber().
|
| Event handlers |
event(),
mousePressEvent(),
mouseReleaseEvent(),
mouseDoubleClickEvent(),
mouseMoveEvent(),
keyPressEvent(),
keyReleaseEvent(),
focusInEvent(),
focusOutEvent(),
wheelEvent(),
enterEvent(),
leaveEvent(),
paintEvent(),
moveEvent(),
resizeEvent(),
closeEvent(),
dragEnterEvent(),
dragMoveEvent(),
dragLeaveEvent(),
dropEvent(),
childEvent(),
showEvent(),
hideEvent(),
customEvent().
|
| Change handlers |
enabledChange(),
fontChange(),
paletteChange(),
styleChange(),
windowActivationChange().
|
| System functions |
parentWidget(),
topLevelWidget(),
reparent(),
polish(),
winId(),
find(),
metric().
|
| What's this help |
customWhatsThis()
|
Internal kernel functions |
focusNextPrevChild(),
wmapper(),
clearWFlags(),
getWFlags(),
setWFlags(),
testWFlags().
|
Every widget's constructor accepts two or three standard arguments:
- QWidget *parent = 0 is the parent of the new widget.
If it is 0 (the default), the new widget will be a top-level window.
If not, it will be a child of parent, and be constrained by parent's geometry (unless you specify WType_TopLevel as
widget flag).
- const char *name = 0 is the widget name of the new
widget. You can access it using name(). The widget name is little
used by programmers but is quite useful with GUI builders such as
Qt Designer (you can name a widget in Qt Designer, and
connect() to it using the name in your code). The dumpObjectTree()
debugging function also uses it.
- WFlags f = 0 (where available) sets the widget flags; the
default is suitable for almost all widgets, but to get, for
example, a top-level widget without a window system frame, you
must use special flags.
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 specific to it (as all useful widgets
do), 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:
- paintEvent() - called whenever the widget needs to be
repainted. Every widget which displays output must implement it,
and it is wise not to paint on the screen outside
paintEvent().
- resizeEvent() - called when the widget has been resized.
- mousePressEvent() - called when a mouse button is pressed.
There are six mouse-related events, but the mouse press and mouse
release events are by far the most important. A widget receives
mouse press events when the mouse is inside it, or when it has
grabbed the mouse using grabMouse().
- mouseReleaseEvent() - called when a mouse button is released.
A widget receives mouse release events when it has received the
corresponding mouse press event. This means that if the user
presses the mouse inside your widget, then drags the mouse to
somewhere else, then releases, your widget receives the release
event. There is one exception: if a popup menu appears while the
mouse button is held down, this popup immediately steals the mouse
events.
- mouseDoubleClickEvent() - not quite as obvious as it might seem.
If the user double-clicks, the widget receives a mouse press event
(perhaps a mouse move event or two if they don't hold the mouse
quite steady), a mouse release event and finally this event. It is
not possible to distinguish a click from a double click until you've
seen whether the second click arrives. (This is one reason why most GUI
books recommend that double clicks be an extension of single clicks,
rather than trigger a different action.)
If your widget only contains child widgets, you probably do not need to
implement any event handlers. If you want to detect a mouse click in
a child widget call the child's hasMouse() function inside the
parent widget's mousePressEvent().
Widgets that accept keyboard input need to reimplement a few more
event handlers:
- keyPressEvent() - called whenever a key is pressed, and again
when a key has been held down long enough for it to auto-repeat.
Note that the Tab and Shift+Tab keys are only passed to the widget
if they are not used by the focus-change mechanisms. To force those
keys to be processed by your widget, you must reimplement
QWidget::event().
- focusInEvent() - called when the widget gains keyboard focus
(assuming you have called setFocusPolicy()). Well written widgets
indicate that they own the keyboard focus in a clear but discreet
way.
- focusOutEvent() - called when the widget loses keyboard focus.
Some widgets will also need to reimplement some of the less common
event handlers:
- mouseMoveEvent() - called whenever the mouse moves while a
button is held down. This is useful for, for example, dragging. If
you call setMouseTracking(TRUE), you get mouse move events even
when no buttons are held down. (Note that applications which make
use of mouse tracking are often not very useful on low-bandwidth X
connections.) (See also the drag and drop
information.)
- keyReleaseEvent() - called whenever a key is released, and also
while it is held down if the key is auto-repeating. In that case
the widget receives a key release event and immediately a key press
event for every repeat. Note that the Tab and Shift+Tab keys are
only passed to the widget if they are not used by the focus-change
mechanisms. To force those keys to be processed by your widget, you
must reimplement QWidget::event().
- wheelEvent() -- called whenever the user turns the mouse wheel
while the widget has the focus.
- enterEvent() - called when the mouse enters the widget's screen
space. (This excludes screen space owned by any children of the
widget.)
- leaveEvent() - called when the mouse leaves the widget's screen
space.
- moveEvent() - called when the widget has been moved relative to its
parent.
- closeEvent() - called when the user closes the widget (or when
close() is called).
There are also some rather 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 implementing a widget, there are a few more things to
consider.
- 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 almost always useful to reimplement sizeHint() and to set
the correct size policy with setSizePolicy(), so users of your class
can set up layout management more easily. A size policy lets you
supply good defaults for the layout management handling, so that
other widgets can contain and manage yours easily. sizeHint()
indicates a "good" size for the widget.
- If your widget is a top-level window, setCaption() and setIcon() set
the title bar and icon respectively.
See also QEvent, QPainter, QGridLayout, QBoxLayout, and Abstract Widget Classes.
Member Type Documentation
QWidget::BackgroundOrigin
This enum defines the origin used to draw a widget's background
pixmap.
The pixmap is drawn using the:
- QWidget::WidgetOrigin - widget's coordinate system.
- QWidget::ParentOrigin - parent's coordinate system.
- QWidget::WindowOrigin - top-level window's coordinate system.
- QWidget::AncestorOrigin - same origin as the parent uses.
QWidget::FocusPolicy
This enum type defines the various policies a widget can have with
respect to acquiring keyboard focus.
- QWidget::TabFocus - the widget accepts focus by tabbing.
- QWidget::ClickFocus - the widget accepts focus by clicking.
- QWidget::StrongFocus - the widget accepts focus by both tabbing
and clicking. On Mac OS X this will also
be indicate that the widget accepts tab focus
when in 'Text/List focus mode'.
- QWidget::WheelFocus - like StrongFocus plus the widget accepts
focus by using the mouse wheel.
- QWidget::NoFocus - the widget does not accept focus.
Member Function Documentation
explicit 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 its parent is
deleted.
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 0). To customize the frame, set the WStyle_Customize flag OR'ed with any of the Qt::WidgetFlags.
If you add a child widget to an already visible widget you must
explicitly show the child to make it visible.
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 *splashScreen = new QLabel( 0, "mySplashScreen",
WStyle_Customize | WStyle_Splash );
QWidget::~QWidget ()
Destroys the widget.
All this widget's children are deleted first. The application
exits if this widget is the main widget.
bool QWidget::acceptDrops () const
Returns TRUE if drop events are enabled for this widget; otherwise returns FALSE.
See the "acceptDrops" property for details.
void QWidget::adjustSize () [virtual slot]
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 >= 0), otherwise sets the size to the children rectangle (the
union of all child widget geometries).
See also sizeHint and childrenRect.
Example: xform/xform.cpp.
Reimplemented in QMessageBox.
bool QWidget::autoMask () const
Returns TRUE if the auto mask feature is enabled for the widget; otherwise returns FALSE.
See the "autoMask" property for details.
const QBrush & QWidget::backgroundBrush () const
Returns the widget's background brush.
See the "backgroundBrush" property for details.
const QColor & QWidget::backgroundColor () const
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Use paletteBackgroundColor() or eraseColor() instead.
BackgroundMode QWidget::backgroundMode () const
Returns the color role used for painting the background of the widget.
See the "backgroundMode" property for details.
BackgroundOrigin QWidget::backgroundOrigin () const
Returns the origin of the widget's background.
See the "backgroundOrigin" property for details.
const QPixmap * QWidget::backgroundPixmap () const
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Use paletteBackgroundPixmap() or erasePixmap() instead.
Examples: themes/metal.cpp and themes/wood.cpp.
QSize QWidget::baseSize () const
Returns the base size of the widget.
See the "baseSize" property for details.
QString QWidget::caption () const
Returns the window caption (title).
See the "caption" property for details.
QWidget * QWidget::childAt ( int x, int y, bool includeThis = FALSE ) const
Returns the visible child widget at pixel position (x, y) in
the widget's own coordinate system.
If includeThis is TRUE, and there is no child visible at (x, y), the widget itself is returned.
QWidget * QWidget::childAt ( const QPoint & p, bool includeThis = FALSE ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns the visible child widget at point p in the widget's own
coordinate system.
If includeThis is TRUE, and there is no child visible at p,
the widget itself is returned.
QRect QWidget::childrenRect () const
Returns the bounding rectangle of the widget's children.
See the "childrenRect" property for details.
QRegion QWidget::childrenRegion () const
Returns the combined region occupied by the widget's children.
See the "childrenRegion" property for details.
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 focus, setFocus(), focusInEvent(), focusOutEvent(), focusPolicy, 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().
QRegion QWidget::clipRegion () const
Returns the unobscured region where paint events can occur.
For visible widgets, this is an approximation of the area not
covered by other widgets; otherwise, this is an empty region.
The repaint() function calls this function if necessary, so in
general you do not need to call it.
bool QWidget::close () [slot]
Closes this widget. Returns TRUE if the widget was closed;
otherwise returns 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.
Examples: dialog/mainwindow.cpp, mdi/application.cpp, popup/popup.cpp, and toplevel/options.ui.h.
bool QWidget::close ( bool alsoDelete ) [virtual]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Closes this widget. Returns TRUE if the widget was closed;
otherwise returns 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. A close events is delivered to the widget
no matter if the widget is visible or not.
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().
void QWidget::closeEvent ( QCloseEvent * e ) [virtual protected]
This event handler, for event e, 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.
Examples: action/application.cpp, application/application.cpp, chart/chartform.cpp, i18n/mywidget.cpp, mdi/application.cpp, popup/popup.cpp, and qwerty/qwerty.cpp.
const QColorGroup & QWidget::colorGroup () const
Returns the current color group of the widget palette.
See the "colorGroup" property for details.
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::contextMenuEvent ( QContextMenuEvent * e ) [virtual protected]
This event handler, for event e, can be reimplemented in a
subclass to receive widget context menu events.
The default implementation calls e->ignore(), which rejects the
context event. See the QContextMenuEvent documentation for
more details.
See also event() and QContextMenuEvent.
Example: menu/menu.cpp.
void QWidget::create ( WId window = 0, bool initializeWindow = TRUE, bool destroyOldWindow = TRUE ) [virtual protected]
Creates a new widget window if window is 0, 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 only makes 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 cursor shape for this widget.
See the "cursor" property for details.
bool QWidget::customWhatsThis () const [virtual]
Returns TRUE if the widget wants to handle What's This help manually; otherwise returns FALSE.
See the "customWhatsThis" property for details.
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.
Example: iconview/simple_dd/main.cpp.
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.
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.
void QWidget::drawText ( int x, int y, const QString & str )
Draws the string 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 font, foregroundColor(), and QPainter::drawText().
void QWidget::drawText ( const QPoint & pos, const QString & str )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Draws the string str at position pos.
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.
Example: iconview/simple_dd/main.cpp.
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 enabled, enabled, repaint(), update(), and clipRegion().
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().
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 behaves essentially like the above function.
This version erases the entire widget.
void QWidget::erase ( const QRect & r )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Erases the specified area r in the widget without generating a
paint event.
void QWidget::erase ( const QRegion & reg )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Erases the area defined by reg, without generating a paint event.
Child widgets are not affected.
const QColor & QWidget::eraseColor () const
Returns the erase color of the widget.
See also setEraseColor(), setErasePixmap(), and backgroundColor().
const QPixmap * QWidget::erasePixmap () const
Returns the widget's erase pixmap.
See also setErasePixmap() and eraseColor().
bool QWidget::event ( QEvent * e ) [virtual protected]
This is the main event handler; it handles event e. You can
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 and 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 (i.e. someone wanted the event); otherwise returns FALSE.
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 on the underlying window
system, see qwindowdefs.h for the actual definition. If there
is no widget with this identifier, 0 is returned.
QFocusData * QWidget::focusData () [protected]
Returns 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 (except for toplevel
widgets that do not specify a focusPolicy() ). It also calls
setMicroFocusHint(), hinting any system-specific input tools about
the focus of the user's attention.
See also focusOutEvent(), focusPolicy, keyPressEvent(), keyReleaseEvent(), event(), and QFocusEvent.
bool QWidget::focusNextPrevChild ( bool next ) [virtual protected]
Finds a new widget to give the keyboard focus to, as appropriate
for Tab and 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, it searches "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 or
first link on the "page".
Child widgets call focusNextPrevChild() on their parent widgets,
but only the top-level widget decides where to redirect focus. By
overriding this method for an object, you thus gain control of
focus traversal for all child widgets.
Warning: QScrollView uses it own logic for this function, which
does the right thing in most cases. But if you are using a
QScrollView and want complete control of the focus chain you'll
need to override QScrollView::focusNextPrevChild() and your
top-level widgets' focusNextPrevChild() functions.
See also focusData().
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 updates the widget (except for toplevel
widgets that do not specify a focusPolicy() ). It also calls
setMicroFocusHint(), hinting any system-specific input tools about
the focus of the user's attention.
See also focusInEvent(), focusPolicy, keyPressEvent(), keyReleaseEvent(), event(), and QFocusEvent.
Example: qmag/qmag.cpp.
FocusPolicy QWidget::focusPolicy () const
Returns the way the widget accepts keyboard focus.
See the "focusPolicy" property for details.
QWidget * QWidget::focusProxy () const
Returns 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.
See the "font" property for details.
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 font, font, update(), and updateGeometry().
QFontInfo QWidget::fontInfo () const
Returns the font info for the widget's current font.
Equivalent to QFontInto(widget->font()).
See also font, fontMetrics(), and font.
QFontMetrics QWidget::fontMetrics () const
Returns the font metrics for the widget's current font.
Equivalent to QFontMetrics(widget->font()).
See also font, fontInfo(), and font.
Examples: drawdemo/drawdemo.cpp and qmag/qmag.cpp.
const QColor & QWidget::foregroundColor () const
Same as paletteForegroundColor()
QRect QWidget::frameGeometry () const
Returns geometry of the widget relative to its parent including any window frame.
See the "frameGeometry" property for details.
QSize QWidget::frameSize () const
Returns the size of the widget including any window frame.
See the "frameSize" property for details.
const QRect & QWidget::geometry () const
Returns the geometry of the widget relative to its parent and excluding the window frame.
See the "geometry" property for details.
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 the keyboard input.
This widget reveives all keyboard events until releaseKeyboard()
is called; other widgets get no keyboard events at all. Mouse
events are not affected. Use grabMouse() if you want to grab that.
The focus widget is not affected, except that it doesn't receive
any keyboard events. setFocus() moves the focus as usual, but the
new focus widget receives keyboard events only after
releaseKeyboard() is called.
If a different widget is currently grabbing keyboard input, that
widget's grab is released first.
See also releaseKeyboard(), grabMouse(), releaseMouse(), and focusWidget().
void QWidget::grabMouse ()
Grabs the mouse input.
This widget receives all mouse events until releaseMouse() is
called; other widgets get no mouse events at all. Keyboard
events are not affected. Use grabKeyboard() if you want to grab
that.
Warning: Bugs in mouse-grabbing applications very often lock the
terminal. Use this function with extreme caution, and consider
using the -nograb command line option while debugging.
It is almost never necessary to grab the mouse when using Qt, as
Qt grabs and releases it sensibly. In particular, Qt grabs the
mouse when a mouse button is pressed and keeps it until the last
button is released.
Note that only visible widgets can grab mouse input. If
isVisible() returns FALSE for a widget, that widget cannot call
grabMouse().
See also releaseMouse(), grabKeyboard(), releaseKeyboard(), grabKeyboard(), and focusWidget().
void QWidget::grabMouse ( const QCursor & cursor )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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 cursor.
bool QWidget::hasFocus () const
Returns TRUE if this widget (or its focus proxy) has the keyboard input focus; otherwise returns FALSE.
See the "focus" property for details.
bool QWidget::hasMouse () const
Returns TRUE if the widget is under the mouse cursor; otherwise returns FALSE.
See the "underMouse" property for details.
bool QWidget::hasMouseTracking () const
Returns TRUE if mouse tracking is enabled for the widget; otherwise returns FALSE.
See the "mouseTracking" property for details.
int QWidget::height () const
Returns the height of the widget excluding any window frame.
See the "height" property for details.
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 QMenuBar and QTextEdit.
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 hideEvent(), hidden, show(), showMinimized(), visible, and close().
Examples: mdi/application.cpp, popup/popup.cpp, progress/progress.cpp, scrollview/scrollview.cpp, webbrowser/mainwindow.ui.h, and xform/xform.cpp.
Reimplemented in 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 immediately after they have been
hidden.
See also event() and QHideEvent.
Reimplemented in QScrollBar.
const QPixmap * QWidget::icon () const
Returns the widget's icon.
See the "icon" property for details.
QString QWidget::iconText () const
Returns the widget's icon text.
See the "iconText" property for details.
void QWidget::iconify () [slot]
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
void QWidget::imComposeEvent ( QIMEvent * e ) [virtual protected]
This event handler, for event e, can be reimplemented in a
subclass to receive Input Method composition events. This handler
is called when the user has entered some text using an Input Method.
The default implementation calls e->ignore(), which rejects the
Input Method event. See the QIMEvent documentation for more
details.
See also event() and QIMEvent.
void QWidget::imEndEvent ( QIMEvent * e ) [virtual protected]
This event handler, for event e, can be reimplemented in a
subclass to receive Input Method composition events. This handler
is called when the user has finished inputting text via an Input
Method.
The default implementation calls e->ignore(), which rejects the
Input Method event. See the QIMEvent documentation for more
details.
See also event() and QIMEvent.
void QWidget::imStartEvent ( QIMEvent * e ) [virtual protected]
This event handler, for event e, can be reimplemented in a
subclass to receive Input Method composition events. This handler
is called when the user begins entering text using an Input Method.
The default implementation calls e->ignore(), which rejects the
Input Method event. See the QIMEvent documentation for more
details.
See also event() and QIMEvent.
bool QWidget::isActiveWindow () const
Returns TRUE if this widget is the active window; otherwise returns FALSE.
See the "isActiveWindow" property for details.
bool QWidget::isDesktop () const
Returns TRUE if the widget is a desktop widget, i.e. represents the desktop; otherwise returns FALSE.
See the "isDesktop" property for details.
bool QWidget::isDialog () const
Returns TRUE if the widget is a dialog widget; otherwise returns FALSE.
See the "isDialog" property for details.
bool QWidget::isEnabled () const
Returns TRUE if the widget is enabled; otherwise returns FALSE.
See the "enabled" property for details.
bool QWidget::isEnabledTo ( QWidget * ancestor ) const
Returns TRUE if this widget would become enabled if ancestor is
enabled; otherwise returns FALSE.
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 enabled and enabled.
bool QWidget::isEnabledToTLW () const
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
This function is deprecated. It is equivalent to isEnabled()
bool QWidget::isFocusEnabled () const
Returns TRUE if the widget accepts keyboard focus; otherwise returns FALSE.
See the "focusEnabled" property for details.
bool QWidget::isFullScreen () const
Returns TRUE if the widget is full screen; otherwise returns FALSE.
See the "fullScreen" property for details.
bool QWidget::isHidden () const
Returns TRUE if the widget is explicitly hidden; otherwise returns FALSE.
See the "hidden" property for details.
bool QWidget::isInputMethodEnabled () const
Returns enables or disables the use of input methods for this widget.
See the "inputMethodEnabled" property for details.
bool QWidget::isMaximized () const
Returns TRUE if this widget is maximized; otherwise returns FALSE.
See the "maximized" property for details.
bool QWidget::isMinimized () const
Returns TRUE if this widget is minimized (iconified); otherwise returns FALSE.
See the "minimized" property for details.
bool QWidget::isModal () const
Returns TRUE if the widget is a modal widget; otherwise returns FALSE.
See the "isModal" property for details.
bool QWidget::isPopup () const
Returns TRUE if the widget is a popup widget; otherwise returns FALSE.
See the "isPopup" property for details.
bool QWidget::isShown () const
Returns TRUE if the widget is shown; otherwise returns FALSE.
See the "shown" property for details.
bool QWidget::isTopLevel () const
Returns TRUE if the widget is a top-level widget; otherwise returns FALSE.
See the "isTopLevel" property for details.
bool QWidget::isUpdatesEnabled () const
Returns TRUE if updates are enabled; otherwise returns FALSE.
See the "updatesEnabled" property for details.
bool QWidget::isVisible () const
Returns TRUE if the widget is visible; otherwise returns FALSE.
See the "visible" property for details.
bool QWidget::isVisibleTo ( QWidget * ancestor ) const
Returns TRUE if this widget would become visible if ancestor is
shown; otherwise returns FALSE.
The TRUE case occurs if neither the widget itself nor any parent
up to but excluding ancestor has been explicitly hidden.
This function will still return TRUE if the widget is obscured by
other windows on the screen, but could be physically visible if it
or they were to be moved.
isVisibleTo(0) is identical to isVisible().
See also show(), hide(), and visible.
bool QWidget::isVisibleToTLW () const
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
This function is deprecated. It is equivalent to isVisible()
void QWidget::keyPressEvent ( QKeyEvent * e ) [virtual protected]
This event handler, for event e, 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 the user
presses Esc. Otherwise the event is ignored.
See also keyReleaseEvent(), QKeyEvent::ignore(), focusPolicy, focusInEvent(), focusOutEvent(), event(), and QKeyEvent.
Example: picture/picture.cpp.
Reimplemented in QLineEdit and QTextEdit.
void QWidget::keyReleaseEvent ( QKeyEvent * e ) [virtual protected]
This event handler, for event e, 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(), focusPolicy, focusInEvent(), focusOutEvent(), event(), and QKeyEvent.
QWidget * QWidget::keyboardGrabber () [static]
Returns 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().
QLayout * QWidget::layout () const
Returns the layout engine that manages the geometry of this
widget's children.
If the widget does not have a layout, layout() returns 0.
See also sizePolicy.
Examples: chart/optionsform.cpp and fonts/simple-qfont-demo/viewer.cpp.
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().
void QWidget::lower () [slot]
Lowers the widget to the bottom of the parent widget's stack.
After this call the widget will be visually behind (and therefore
obscured by) any overlapping sibling widgets.
See also raise() and stackUnder().
bool QWidget::macEvent ( MSG * ) [virtual protected]
This special event handler can be reimplemented in a subclass to
receive native Macintosh events.
In your reimplementation of this function, if you want to stop the
event being handled by Qt, return TRUE. If you return FALSE, this
native event is passed back to Qt, which translates the event into
a Qt event and sends it to the widget.
Warning: This function is not portable.
See also QApplication::macEventFilter().
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. The parent
must not be 0 and must be a parent of the calling widget.
See also mapTo(), mapFromParent(), mapFromGlobal(), and underMouse.
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(), mapFromGlobal(), and underMouse.
QPoint QWidget::mapTo ( QWidget * parent, const QPoint & pos ) const
Translates the widget coordinate pos to the coordinate system
of parent. The parent must not be 0 and must be a parent
of the calling widget.
See also mapFrom(), mapToParent(), mapToGlobal(), and underMouse.
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().
Example: scribble/scribble.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(), mapToGlobal(), and underMouse.
int QWidget::maximumHeight () const
Returns the widget's maximum height.
See the "maximumHeight" property for details.
QSize QWidget::maximumSize () const
Returns the widget's maximum size.
See the "maximumSize" property for details.
int QWidget::maximumWidth () const
Returns the widget's maximum width.
See the "maximumWidth" property for details.
int QWidget::metric ( int m ) const [virtual protected]
Internal implementation of the virtual QPaintDevice::metric()
function.
Use the QPaintDeviceMetrics class instead.
m is the metric to get.
QRect QWidget::microFocusHint () const
Returns the currently set micro focus hint for this widget.
See the "microFocusHint" property for details.
int QWidget::minimumHeight () const
Returns the widget's minimum height.
See the "minimumHeight" property for details.
QSize QWidget::minimumSize () const
Returns the widget's minimum size.
See the "minimumSize" property for details.
QSize QWidget::minimumSizeHint () const [virtual]
Returns the recommended minimum size for the widget.
See the "minimumSizeHint" property for details.
Reimplemented in QLineEdit.
int QWidget::minimumWidth () const
Returns the widget's minimum width.
See the "minimumWidth" property for details.
void QWidget::mouseDoubleClickEvent ( QMouseEvent * e ) [virtual protected]
This event handler, for event e, 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.
QWidget * QWidget::mouseGrabber () [static]
Returns 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 * e ) [virtual protected]
This event handler, for event e, 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 pressed while the mouse is being moved. If mouse
tracking is switched on, mouse move events occur even if no mouse
button is pressed.
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's hand shakes.
This is a feature of the underlying window system, not Qt.
See also mouseTracking, mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), event(), and QMouseEvent.
Examples: aclock/aclock.cpp, drawlines/connect.cpp, iconview/simple_dd/main.cpp, life/life.cpp, popup/popup.cpp, qmag/qmag.cpp, and scribble/scribble.cpp.
Reimplemented in QSizeGrip.
void QWidget::mousePressEvent ( QMouseEvent * e ) [virtual protected]
This event handler, for event e, 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.
Examples: biff/biff.cpp, drawlines/connect.cpp, iconview/simple_dd/main.cpp, life/life.cpp, qmag/qmag.cpp, scribble/scribble.cpp, and tooltip/tooltip.cpp.
Reimplemented in QSizeGrip.
void QWidget::mouseReleaseEvent ( QMouseEvent * e ) [virtual protected]
This event handler, for event e, can be reimplemented in a
subclass to receive mouse release events for the widget.
See also mouseDoubleClickEvent(), mouseMoveEvent(), event(), and QMouseEvent.
Examples: drawlines/connect.cpp, hello/hello.cpp, popup/popup.cpp, qmag/qmag.cpp, scribble/scribble.cpp, showimg/showimg.cpp, and t14/cannon.cpp.
void QWidget::move ( const QPoint & ) [slot]
Sets the position of the widget within its parent widget.
See the "pos" property for details.
void QWidget::move ( int x, int y ) [virtual slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This corresponds to move( QPoint(x, y) ).
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(), pos, and QMoveEvent.
bool QWidget::ownCursor () const
Returns TRUE if the widget uses its own cursor; otherwise returns FALSE.
See the "ownCursor" property for details.
bool QWidget::ownFont () const
Returns TRUE if the widget uses its own font; otherwise returns FALSE.
See the "ownFont" property for details.
bool QWidget::ownPalette () const
Returns TRUE if the widget uses its own palette; otherwise returns FALSE.
See the "ownPalette" property for details.
void QWidget::paintEvent ( QPaintEvent * ) [virtual protected]
This event handler can be reimplemented in a subclass to receive
paint events.
A paint event is a request to repaint all or part of the widget.
It can happen as a result of repaint() or update(), or because the
widget was obscured and has now been uncovered, or for many other
reasons.
Many widgets can simply repaint their entire surface when asked
to, but some slow widgets need to optimize by painting only the
requested region: QPaintEvent::region(). This speed optimization
does not change the result, as painting is clipped to that region
during event processing. QListView and QCanvas do this, for
example.
Qt also tries to speed up painting by merging multiple paint
events into one. When update() is called several times or the
window system sends several paint events, Qt merges these events
into one event with a larger region (see QRegion::unite()).
repaint() does not permit this optimization, so we suggest using
update() when possible.
When the paint event occurs, the update region has normally been
erased, so that you're painting on the widget's background. There
are a couple of exceptions and QPaintEvent::erased() tells you
whether the widget has been erased or not.
The background can be set using setBackgroundMode(),
setPaletteBackgroundColor() or setBackgroundPixmap(). The
documentation for setBackgroundMode() elaborates on the
background; we recommend reading it.
See also event(), repaint(), update(), QPainter, QPixmap, and QPaintEvent.
Examples: drawlines/connect.cpp, forever/forever.cpp, qmag/qmag.cpp, scribble/scribble.cpp, splitter/splitter.cpp, t8/cannon.cpp, and t9/cannon.cpp.
Reimplemented in QButton, QFrame, QGLWidget, QSizeGrip, QStatusBar, and QTabBar.
const QPalette & QWidget::palette () const
Returns the widget's palette.
See the "palette" property for details.
const QColor & QWidget::paletteBackgroundColor () const
Returns the background color of the widget.
See the "paletteBackgroundColor" property for details.
const QPixmap * QWidget::paletteBackgroundPixmap () const
Returns the background pixmap of the widget.
See the "paletteBackgroundPixmap" property for details.
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.
See also palette and palette.
const QColor & QWidget::paletteForegroundColor () const
Returns the foreground color of the widget.
See the "paletteForegroundColor" property for details.
QWidget * QWidget::parentWidget ( bool sameWindow = FALSE ) const
Returns the parent of this widget, or 0 if it does not have any
parent widget. If sameWindow is TRUE and the widget is top
level returns 0; otherwise returns the widget's parent.
Example: mdi/application.cpp.
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 which depends on
having 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 first when reimplementing this
function to ensure that your program does not end up in infinite recursion.
See also constPolish() and QApplication::polish().
Example: menu/menu.cpp.
QPoint QWidget::pos () const
Returns the position of the widget within its parent widget.
See the "pos" property for details.
bool QWidget::qwsEvent ( QWSEvent * ) [virtual protected]
This special event handler can be reimplemented in a subclass to
receive native Qt/Embedded events.
In your reimplementation of this function, if you want to stop the
event being handled by Qt, return TRUE. If you return FALSE, this
native event is passed back to Qt, which translates the event into
a Qt event and sends it to the widget.
Warning: This function is not portable.
See also QApplication::qwsEventFilter().
void QWidget::raise () [slot]
Raises this widget to the top of the parent widget's stack.
After this call the widget will be visually in front of any
overlapping sibling widgets.
See also lower() and stackUnder().
Example: showimg/showimg.cpp.
void QWidget::recreate ( QWidget * parent, WFlags f, const QPoint & p, bool showIt = FALSE )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
This method is provided to aid porting from Qt 1.0 to 2.0. It has
been renamed reparent() in Qt 2.0.
QRect QWidget::rect () const
Returns the internal geometry of the widget excluding any window frame.
See the "rect" property for details.
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().
void QWidget::repaint ( int x, int y, int w, int h, bool erase = TRUE ) [slot]
Repaints the widget directly by calling paintEvent() immediately,
unless updates are disabled or the widget is hidden.
If erase is TRUE, Qt erases the area (x, y, w, h) before the
paintEvent() call.
If w is negative, it is replaced with width() - x, and if
h is negative, it is replaced width height() - y.
We suggest only using repaint() if you need an immediate repaint,
for example during animation. In almost all circumstances update()
is better, as it permits Qt to optimize for speed and minimize
flicker.
Warning: If you call repaint() in a function which may itself be
called from paintEvent(), you may get infinite recursion. The
update() function never causes recursion.
See also update(), paintEvent(), updatesEnabled, and erase().
Example: qwerty/qwerty.cpp.
void QWidget::repaint () [slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This version erases and repaints the entire widget.
void QWidget::repaint ( bool erase ) [slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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 behaves essentially like the above function.
Repaints the widget directly by calling paintEvent() directly,
unless updates are disabled or the widget is hidden.
Erases the widget region r if erase is TRUE.
void QWidget::repaint ( const QRegion & reg, bool erase = TRUE ) [slot]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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.
Only use repaint if your widget needs to be repainted immediately,
for example when doing some animation. In all other cases, use
update(). 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 get infinite recursion. The
update() function never causes recursion.
See also update(), paintEvent(), updatesEnabled, and erase().
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: It is extremely unlikely that you will ever need this
function. If you have a widget that changes its content
dynamically, it is far easier to use QWidgetStack or QWizard.
See also getWFlags().
Example: toplevel/options.ui.h.
void QWidget::reparent (