1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the gui module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qapplication.h"
30
#include "qapplication_p.h"
33
#include "qdesktopwidget.h"
38
#include "qmetaobject.h"
43
#include "qstylefactory.h"
46
#ifndef QT_NO_ACCESSIBILITY
47
#include "qaccessible.h"
50
#include "qt_windows.h"
53
# include "qt_mac_p.h"
56
#include "qwsmanager_qws.h"
60
#include "qwhatsthis.h"
63
#include "qinputcontext.h"
66
#include <private/qwininputcontext_p.h>
70
#include <private/qpaintengine_x11_p.h>
71
#include "qx11info_x11.h"
74
#include "qwidget_p.h"
75
#include "qaction_p.h"
76
#include "qlayout_p.h"
78
QWidgetPrivate::QWidgetPrivate(int version) :
79
QObjectPrivate(version), extra(0), focus_child(0)
83
,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0)
84
,fg_role(QPalette::NoRole)
85
,bg_role(QPalette::NoRole)
89
#elif defined(Q_WS_MAC)
95
if (version != QObjectPrivateVersion)
96
qFatal("Cannot mix incompatible Qt libraries");
99
memset(high_attributes, 0, sizeof(high_attributes));
103
QWidgetPrivate::~QWidgetPrivate()
111
This is an internal function, you should never call this.
113
This function is called to remove focus from associated input
116
\sa QInputContext::unsetFocus()
118
void QWidgetPrivate::unfocusInputContext()
122
QInputContext *qic = q->inputContext();
124
qic->setFocusWidget( 0 );
131
This is an internal function, you should never call this.
133
This function is called to focus associated input context. The
134
code intends to eliminate duplicate focus for the context even if
135
the context is shared between widgets
137
\sa QInputContext::setFocus()
139
void QWidgetPrivate::focusInputContext()
143
QInputContext *qic = q->inputContext();
145
if(qic->focusWidget() != q)
146
qic->setFocusWidget(q);
152
This function returns the QInputContext for this widget. By
153
default the input context is inherited from the widgets
154
parent. For toplevels it is inherited from QApplication.
156
You can override this and set a special input context for this
157
widget by using the setInputContext() method.
159
\sa setInputContext()
161
QInputContext *QWidget::inputContext()
164
if (!testAttribute(Qt::WA_InputMethodEnabled))
169
return qApp->inputContext();
173
This function sets the input context \a context
178
void QWidget::setInputContext(QInputContext *context)
181
if (!testAttribute(Qt::WA_InputMethodEnabled))
190
This function is called when text widgets need to be neutral state to
191
execute text operations properly. See qlineedit.cpp and qtextedit.cpp as
194
Ordinary reset that along with changing focus to another widget,
195
moving the cursor, etc, is implicitly handled via
196
unfocusInputContext() because whether reset or not when such
197
situation is a responsibility of input methods. So we delegate the
198
responsibility to the input context via unfocusInputContext(). See
199
'Preedit preservation' section of the class description of
200
QInputContext for further information.
202
\sa QInputContext, QInputContext::reset()
204
void QWidget::resetInputContext()
209
QInputContext *qic = this->inputContext();
217
\class QWidget qwidget.h
218
\brief The QWidget class is the base class of all user interface objects.
220
\ingroup abstractwidgets
223
The widget is the atom of the user interface: it receives mouse,
224
keyboard and other events from the window system, and paints a
225
representation of itself on the screen. Every widget is
226
rectangular, and they are sorted in a Z-order. A widget is
227
clipped by its parent and by the widgets in front of it.
229
A widget that isn't embedded in a parent widget is called a
230
window. Usually, windows have a frame and a title bar, although
231
it is also possible to create windows without such decoration using
232
suitable \l{Qt::WindowFlags}{window flags}). In Qt,
233
QMainWindow and the various subclasses of QDialog are the most
236
A widget without a parent widget is always an independent window.
238
Non-window widgets are child widgets. These are child windows
239
in their parent widgets. You cannot usually distinguish a child
240
widget from its parent visually. Most other widgets in Qt are
241
useful only as child widgets. (It is possible to make, say, a
242
button into a window, but most people prefer to put
243
their buttons inside other widgets, e.g. QDialog.)
245
If you want to use a QWidget to hold child widgets you will
246
probably want to add a layout to the parent QWidget. (See \link
247
layout.html Layouts\endlink.)
249
QWidget has many member functions, but some of them have little
250
direct functionality: for example, QWidget has a font property,
251
but never uses this itself. There are many subclasses which
252
provide real functionality, such as QPushButton, QListWidget and
255
\section1 Groups of functions:
258
\header \i Context \i Functions
260
\row \i Window functions \i
267
\row \i Top-level windows \i
283
\row \i Window contents \i
336
\row \i Look and feel \i
350
\row \i Keyboard focus functions \i
359
\row \i Mouse and keyboard grabbing \i
367
\row \i Event handlers \i
371
mouseDoubleClickEvent(),
394
\row \i System functions \i
402
\row \i What's this help \i
405
\row \i Focus functions \i
411
Every widget's constructor accepts one or two standard arguments:
413
\i \c{QWidget *parent = 0} is the parent of the new widget.
414
If it is 0 (the default), the new widget will be a window.
415
If not, it will be a child of \e parent, and be constrained by \e
416
parent's geometry (unless you specify \c Qt::Window as
418
\i \c{Qt::WFlags f = 0} (where available) sets the window flags; the
419
default is suitable for almost all widgets, but to get, for
420
example, a window without a window system frame, you
421
must use special flags.
424
The \l widgets/calculator example program is good example of a simple
425
widget. It contains event handlers (as all widgets must),
426
routines that are specific to it (as all useful widgets
427
do), and has children and connections. Everything it does
428
is done in response to an event: this is by far the most common way
429
to design GUI applications.
431
You will need to supply the content for your widgets yourself, but
432
here is a brief run-down of the events, starting with the most common
437
\i paintEvent() - called whenever the widget needs to be
438
repainted. Every widget which displays output must implement it.
439
Painting using a QPainter can only take place in a paintEvent() or
440
a function called by a paintEvent().
442
\i resizeEvent() - called when the widget has been resized.
444
\i mousePressEvent() - called when a mouse button is pressed.
445
There are six mouse-related events, but the mouse press and mouse
446
release events are by far the most important. A widget receives
447
mouse press events when the mouse is inside it, or when it has
448
grabbed the mouse using grabMouse().
450
\i mouseReleaseEvent() - called when a mouse button is released.
451
A widget receives mouse release events when it has received the
452
corresponding mouse press event. This means that if the user
453
presses the mouse inside \e your widget, then drags the mouse to
454
somewhere else, then releases, \e your widget receives the release
455
event. There is one exception: if a popup menu appears while the
456
mouse button is held down, this popup immediately steals the mouse
459
\i mouseDoubleClickEvent() - not quite as obvious as it might seem.
460
If the user double-clicks, the widget receives a mouse press event
461
(perhaps a mouse move event or two if they don't hold the mouse
462
quite steady), a mouse release event and finally this event. It is
463
\e{not possible} to distinguish a click from a double click until you've
464
seen whether the second click arrives. (This is one reason why most GUI
465
books recommend that double clicks be an extension of single clicks,
466
rather than trigger a different action.)
470
If your widget only contains child widgets, you probably do not need to
471
implement any event handlers. If you want to detect a mouse click in
472
a child widget call the child's underMouse() function inside the
473
parent widget's mousePressEvent().
475
Widgets that accept keyboard input need to reimplement a few more
480
\i keyPressEvent() - called whenever a key is pressed, and again
481
when a key has been held down long enough for it to auto-repeat.
482
Note that the Tab and Shift+Tab keys are only passed to the widget
483
if they are not used by the focus-change mechanisms. To force those
484
keys to be processed by your widget, you must reimplement
487
\i focusInEvent() - called when the widget gains keyboard focus
488
(assuming you have called setFocusPolicy()). Well written widgets
489
indicate that they own the keyboard focus in a clear but discreet
492
\i focusOutEvent() - called when the widget loses keyboard focus.
496
Some widgets will also need to reimplement some of the less common
501
\i mouseMoveEvent() - called whenever the mouse moves while a
502
button is held down. This is useful for, for example, dragging. If
503
you call setMouseTracking(true), you get mouse move events even
504
when no buttons are held down. (See also the \link dnd.html drag
505
and drop\endlink information.)
507
\i keyReleaseEvent() - called whenever a key is released, and also
508
while it is held down if the key is auto-repeating. In that case
509
the widget receives a key release event and immediately a key press
510
event for every repeat. Note that the Tab and Shift+Tab keys are
511
only passed to the widget if they are not used by the focus-change
512
mechanisms. To force those keys to be processed by your widget, you
513
must reimplement QWidget::event().
515
\i wheelEvent() -- called whenever the user turns the mouse wheel
516
while the widget has the focus.
518
\i enterEvent() - called when the mouse enters the widget's screen
519
space. (This excludes screen space owned by any children of the
522
\i leaveEvent() - called when the mouse leaves the widget's screen
525
\i moveEvent() - called when the widget has been moved relative to its
528
\i closeEvent() - called when the user closes the widget (or when
533
There are also some rather obscure events. They are listed in
534
\c qevent.h and you need to reimplement event() to handle them.
535
The default implementation of event() handles Tab and Shift+Tab
536
(to move the keyboard focus), and passes on most other events to
537
one of the more specialized handlers above.
539
When implementing a widget, there are a few more things to
544
\i In the constructor, be sure to set up your member variables
545
early on, before there's any chance that you might receive an event.
547
\i It is almost always useful to reimplement sizeHint() and to set
548
the correct size policy with setSizePolicy(), so users of your class
549
can set up layout management more easily. A size policy lets you
550
supply good defaults for the layout management handling, so that
551
other widgets can contain and manage yours easily. sizeHint()
552
indicates a "good" size for the widget.
554
\i If your widget is a window, setWindowTitle() and
555
setWindowIcon() set the title bar and icon respectively.
559
From Qt 4.0, QWidget automatically double-buffers its painting, so
560
there's no need to write double-buffering code in paintEvent() to
563
\sa QEvent, QPainter, QGridLayout, QBoxLayout
567
QWidgetMapper *QWidgetPrivate::mapper = 0; // app global widget mapper
570
/*****************************************************************************
571
QWidget utility functions
572
*****************************************************************************/
575
static QFont qt_naturalWidgetFont(QWidget* w) {
576
QFont naturalfont = QApplication::font(w);
577
if (! w->isWindow()) {
578
if (! naturalfont.isCopyOf(QApplication::font()))
579
naturalfont = naturalfont.resolve(w->parentWidget()->font());
581
naturalfont = w->parentWidget()->font();
583
naturalfont.resolve(0);
587
static QPalette qt_naturalWidgetPalette(QWidget* w) {
588
QPalette naturalpalette = QApplication::palette(w);
589
if (! w->isWindow()) {
590
if (! naturalpalette.isCopyOf(QApplication::palette()))
591
naturalpalette = naturalpalette.resolve(w->parentWidget()->palette());
593
naturalpalette = w->parentWidget()->palette();
595
naturalpalette.resolve(0);
596
return naturalpalette;
600
/*****************************************************************************
601
QWidget member functions
602
*****************************************************************************/
607
\i Qt::WA_WState_Created The widget has a valid winId().
608
\i Qt::WA_WState_Visible The widget is currently visible.
609
\i Qt::WA_WState_Hidden The widget is hidden, i.e. it won't
610
become visible unless you call show() on it. Qt::WA_WState_Hidden
611
implies !Qt::WA_WState_Visible.
612
\i Qt::WA_WState_CompressKeys Compress keyboard events.
613
\i Qt::WA_WState_BlockUpdates Repaints and updates are disabled.
614
\i Qt::WA_WState_InPaintEvent Currently processing a paint event.
615
\i Qt::WA_WState_Reparented The widget has been reparented.
616
\i Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending.
617
\i Qt::WA_WState_DND The widget supports drag and drop, see setAcceptDrops(). ### depricated
622
Constructs a widget which is a child of \a parent, with widget
625
If \a parent is 0, the new widget becomes a window. If
626
\a parent is another widget, this widget becomes a child window
627
inside \a parent. The new widget is deleted when its \a parent is
630
The widget flags argument, \a f, is normally 0, but it can be set
631
to customize the frame of a window (i.e. \a
632
parent must be 0). To customize the frame, use a value composed
633
from the bitwise OR of any of the \l{Qt::WindowFlags}{window flags}.
635
If you add a child widget to an already visible widget you must
636
explicitly show the child to make it visible.
638
Note that the X11 version of Qt may not be able to deliver all
639
combinations of style flags on all systems. This is because on
640
X11, Qt can only ask the window manager, and the window manager
641
can override the application's settings. On Windows, Qt can set
642
whatever flags you want.
645
QWidget::QWidget(QWidget *parent, Qt::WFlags f)
646
: QObject(*new QWidgetPrivate, ((parent && (parent->windowType() == Qt::Desktop)) ? 0 : parent)), QPaintDevice()
656
QWidget::QWidget(QWidget *parent, const char *name, Qt::WFlags f)
657
: QObject(*new QWidgetPrivate, ((parent && (parent->windowType() == Qt::Desktop)) ? 0 : parent)), QPaintDevice()
666
QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WFlags f)
667
: QObject(dd, ((parent && (parent->windowType() == Qt::Desktop)) ? 0 : parent)), QPaintDevice()
675
int QWidget::devType() const
677
return QInternal::Widget;
680
void QWidgetPrivate::init(Qt::WFlags f)
684
if (qApp->type() == QApplication::Tty)
685
qWarning("QWidget: Cannot create a QWidget when no GUI is being used");
687
#ifdef QT_THREAD_SUPPORT
689
Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",
690
"Widgets must be created in the GUI thread.");
694
data.fstrut_dirty = 1;
697
data.widget_attributes = 0;
698
data.window_flags = f;
699
data.window_state = 0;
700
data.focus_policy = 0;
701
data.context_menu_policy = Qt::DefaultContextMenu;
703
data.sizehint_forced = 0;
706
data.in_set_window_state = 0;
708
q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in create()
710
q->create(); // platform-dependent init
711
#if defined(Q_WS_X11)
712
data.fnt.x11SetScreen(xinfo.screen());
715
if (!(q->windowType() == Qt::Desktop))
716
updateSystemBackground();
718
if (QApplication::isRightToLeft())
719
q->setAttribute(Qt::WA_RightToLeft);
721
extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
722
if(!qt_mac_is_macdrawer(q)) //special case
723
q->setAttribute(Qt::WA_WState_Hidden);
725
q->setAttribute(Qt::WA_WState_Hidden);
729
QWidget *parentWidget = q->parentWidget();
731
data.pal = parentWidget->data->pal;
734
data.fnt = parentWidget->data->fnt;
736
// propagate enabled state
737
if (!parentWidget->isEnabled())
738
q->setAttribute(Qt::WA_Disabled, true);
739
// propgate updates enabled state
740
if (!parentWidget->updatesEnabled())
741
q->setAttribute(Qt::WA_UpdatesDisabled, true);
742
//propagate layout direction
743
if (parentWidget->testAttribute(Qt::WA_RightToLeft))
744
q->setAttribute(Qt::WA_RightToLeft);
745
// new widgets do not show up in already visible parents
746
if (parentWidget->isVisible())
747
q->setAttribute(Qt::WA_WState_Hidden);
753
// insert at the end of the focus chain
754
QWidget *focus_handler = q->window();
755
QWidget *w = focus_handler;
756
while (w->d_func()->focus_next != focus_handler)
757
w = w->d_func()->focus_next;
758
w->d_func()->focus_next = q;
759
focus_next = focus_handler;
762
q->setAttribute(Qt::WA_PendingMoveEvent);
763
q->setAttribute(Qt::WA_PendingResizeEvent);
765
if (++QWidgetPrivate::instanceCounter > QWidgetPrivate::maxInstances)
766
QWidgetPrivate::maxInstances = QWidgetPrivate::instanceCounter;
768
QEvent e(QEvent::Create);
769
QApplication::sendEvent(q, &e);
770
QApplication::postEvent(q, new QEvent(QEvent::PolishRequest));
772
extraPaintEngine = 0;
774
// send and post remaining QObject events
775
if (q->parent() && sendChildEvents) {
776
QChildEvent e(QEvent::ChildAdded, q);
777
QApplication::sendEvent(q->parent(), &e);
779
QApplication::postEvent(q->parent(), new QChildEvent(QEvent::ChildInserted, q));
786
Creates a new widget window if \a window is 0, otherwise sets the
787
widget's window to \a window.
789
Initializes the window (sets the geometry etc.) if \a
790
initializeWindow is true. If \a initializeWindow is false, no
791
initialization is performed. This parameter only makes sense if \a
792
window is a valid window.
794
Destroys the old window if \a destroyOldWindow is true. If \a
795
destroyOldWindow is false, you are responsible for destroying the
796
window yourself (using platform native code).
798
The QWidget constructor calls create(0,true,true) to create a
799
window for this widget.
802
void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
805
if (testAttribute(Qt::WA_WState_Created) && window == 0)
807
setAttribute(Qt::WA_WState_Created); // set created flag
809
Qt::WindowType type = windowType();
810
Qt::WindowFlags &flags = data->window_flags;
812
if (type == Qt::Widget && !parentWidget()) {
817
if (flags & Qt::WStaticContents)
818
setAttribute(Qt::WA_StaticContents);
819
if (flags & Qt::WDestructiveClose)
820
setAttribute(Qt::WA_DeleteOnClose);
821
if (flags & Qt::WShowModal)
822
setAttribute(Qt::WA_ShowModal);
823
if (flags & Qt::WMouseNoMask)
824
setAttribute(Qt::WA_MouseNoMask);
825
if (flags & Qt::WGroupLeader)
826
setAttribute(Qt::WA_GroupLeader);
827
if (flags & Qt::WNoMousePropagation)
828
setAttribute(Qt::WA_NoMousePropagation);
830
if(type == Qt::Dialog && !testAttribute(Qt::WA_ShowModal)
831
&& parentWidget() && parentWidget()->testAttribute(Qt::WA_ShowModal))
832
setAttribute(Qt::WA_ShowModal);
834
if ( type != Qt::Widget && type != Qt::Window)
835
setAttribute(Qt::WA_QuitOnClose, false);
837
d->create_sys(window, initializeWindow, destroyOldWindow);
840
extern void qt_eval_init_widget(QWidget *w);
841
qt_eval_init_widget(this);
848
All this widget's children are deleted first. The application
849
exits if this widget is the main widget.
855
#if defined (QT_CHECK_STATE)
856
if (paintingActive())
857
qWarning("%s (%s): deleted while being painted", className(), name());
860
// remove all actions from this widget
861
for (int i = 0; i < d->actions.size(); ++i) {
862
QActionPrivate *apriv = d->actions.at(i)->d_func();
863
apriv->widgets.removeAll(this);
867
// Remove all shortcuts grabbed by this
868
// widget, unless application is closing
869
if (!QApplicationPrivate::is_app_closing && testAttribute(Qt::WA_GrabbedShortcut))
870
qApp->d_func()->shortcutMap.removeShortcut(0, this, QKeySequence());
872
// delete layout while we still are a valid widget
876
// Remove myself focus list
877
// ### Focus: maybe remove children aswell?
879
while (w->d_func()->focus_next != this)
880
w = w->d_func()->focus_next;
881
w->d_func()->focus_next = d_func()->focus_next;
882
d_func()->focus_next = 0;
885
if (QApplicationPrivate::main_widget == this) { // reset main widget
886
QApplicationPrivate::main_widget = 0;
893
if (isWindow() && isVisible() && winId())
896
// A parent widget must destroy all its children before destroying itself
897
while (!d->children.isEmpty())
898
delete d->children.takeFirst();
900
QApplication::removePostedEvents(this);
902
destroy(); // platform-dependent cleanup
904
--QWidgetPrivate::instanceCounter;
906
QEvent e(QEvent::Destroy);
907
QCoreApplication::sendEvent(this, &e);
910
int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances
911
int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances
913
void QWidgetPrivate::setWinId(WId id) // set widget identifier
916
if (!mapper) // mapper destroyed
919
mapper->remove(data.winid);
922
#if defined(Q_WS_X11)
923
hd = id; // X11: hd == ident
926
mapper->insert(data.winid, q);
929
void QWidgetPrivate::createTLExtra()
933
if (!extra->topextra) {
934
QTLWExtra* x = extra->topextra = new QTLWExtra;
935
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined (Q_WS_QWS)
938
#ifndef QT_NO_WIDGET_TOPEXTRA
942
x->fleft = x->fright = x->ftop = x->fbottom = 0;
943
x->incw = x->inch = 0;
944
x->basew = x->baseh = 0;
945
x->normalGeometry = QRect(0,0,-1,-1);
946
#if defined(Q_WS_X11)
949
x->spont_unmapped = 0;
955
#if defined(Q_WS_QWS)
956
x->inPaintTransaction = false;
958
#if !defined(QT_NO_QWS_MANAGER)
968
Creates the widget extra data.
971
void QWidgetPrivate::createExtra()
973
if (!extra) { // if not exists
975
extra->minw = extra->minh = 0;
976
extra->maxw = extra->maxh = QWIDGETSIZE_MAX;
977
extra->explicitMinSize = 0;
983
extra->size_policy = QSizePolicy(QSizePolicy::Preferred,
984
QSizePolicy::Preferred);
992
Deletes the widget extra data.
995
void QWidgetPrivate::deleteExtra()
997
if (extra) { // if exists
1002
if (extra->topextra) {
1004
#ifndef QT_NO_WIDGET_TOPEXTRA
1005
delete extra->topextra->icon;
1006
delete extra->topextra->iconPixmap;
1008
#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
1009
delete extra->topextra->qwsManager;
1011
delete extra->topextra;
1014
// extra->xic destroyed in QWidget::destroy()
1020
Returns true if the background is inherited; otherwise returns
1023
A widget does not inherit its parent's background if
1024
setBackgroundRole() was called, or a brush is defined for the
1028
bool QWidgetPrivate::isBackgroundInherited() const
1032
// windows do not inherit their background
1033
if (q->isWindow() || q->windowType() == Qt::SubWindow)
1036
if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_NoBackground))
1039
const QPalette &pal = q->palette();
1040
QPalette::ColorRole bg = q->backgroundRole();
1041
QBrush brush = pal.brush(bg);
1043
// non opaque brushes leaves us no choice, we must inherit
1044
if (!brush.isOpaque())
1047
// if we have a background role set, or a custom brush for the
1048
// background role, then the background is not inherited
1049
if (QPalette::ColorRole(bg_role) != QPalette::NoRole || (pal.resolve() & (1<<bg)))
1052
if (brush.style() == Qt::SolidPattern) {
1053
// the background is just a solid color. If there is no
1054
// propagated contents, then we claim as performance
1055
// optimization that it was not inheritet. This is the normal
1056
// case in standard Windows or Motif style.
1057
const QWidget *w = q->parentWidget();
1058
if (!w->testAttribute(Qt::WA_ContentsPropagated) && !w->d_func()->isBackgroundInherited())
1066
In case a widget inherits its parent's pixmap background or content,
1067
and possibly propagates it further to its own children, this
1068
function updates everthing that needs to be updated after a move.
1070
This is necessary because the pixmap offset has changed. This is not
1071
necessary on Mac OS X because due to the composite manager we get
1072
this for free, and as a result doing it here will actually force
1073
more paints than are necessary, this is a NO-OP for a composited
1074
windowing system like Mac OS X.
1076
void QWidgetPrivate::updateInheritedBackground()
1078
#if !defined(Q_WS_MAC) && !defined(Q_WS_QWS)
1080
if (!q->isVisible() || !isBackgroundInherited())
1083
for (int i = 0; i < children.size(); ++i)
1084
if (QWidget *w = qobject_cast<QWidget *>(children.at(i)))
1085
w->d_func()->updateInheritedBackground();
1090
In case a widget propagates its or its ancestor's contents to its
1091
children, this function updates everything that needs to be updated
1094
Call this only when Qt::WA_ContentsPropagated is set. This is not
1095
necessary on Mac OS X because due to the composite manager we get
1096
this for free, and as a result doing it here will actually force
1097
more paints than are necessary, this is a NO-OP for a composited
1098
windowing system like Mac OS X.
1100
void QWidgetPrivate::updatePropagatedBackground(const QRegion *reg)
1102
#if !defined(Q_WS_MAC) && !defined(Q_WS_QWS)
1103
for (int i = 0; i < children.size(); ++i) {
1104
if (QWidget *w = qobject_cast<QWidget*>(children.at(i))) {
1105
if (reg && !reg->boundingRect().intersects(w->geometry()))
1107
w->d_func()->updateInheritedBackground();
1116
void QWidgetPrivate::composeBackground(const QRect &crect)
1121
//QColor bgCol = QColor::fromHsv(double(ii%5)/5.0, double(ii%33+22)/55.0, double(ii%17+33)/50.0);
1122
QColor bgCol = QColor::fromHsv((ii%5*360)/5, (255*(ii%33+22))/55, (255*(ii%17+33)/50));
1123
QPainter bgPainter(q);
1124
bgPainter.fillRect(crect, bgCol);
1131
QVector<QWidget*> layers;
1135
// Build the stack of widgets to composite
1136
while (w->d_func()->isBackgroundInherited()) {
1138
layers += (w = w->parentWidget());
1142
for (int i=layers.size() - 1; i>=0; --i) {
1145
// Remove the offset for previous layer.
1149
// Do the background if needed.
1150
QBrush bgBrush = w->palette().brush(w->backgroundRole());
1151
if (w == top || (!bgBrush.isOpaque() && w->testAttribute(Qt::WA_SetPalette))) {
1152
QPainter bgPainter(q);
1153
bgPainter.setBrushOrigin(-offset);
1154
bgPainter.fillRect(crect, bgBrush);
1157
// Propagate contents if enabled and w is not the actual widget.
1158
if (w->testAttribute(Qt::WA_ContentsPropagated) && i>0) {
1159
// Setup redirection from w to this widget.
1161
rr.translate(offset);
1162
bool was_in_paint_event = w->testAttribute(Qt::WA_WState_InPaintEvent);
1163
w->setAttribute(Qt::WA_WState_InPaintEvent);
1164
QPainter::setRedirected(w, q, offset);
1166
QApplication::sendEvent(w, &e);
1167
w->setAttribute(Qt::WA_WState_InPaintEvent, was_in_paint_event);
1168
QPainter::restoreRedirected(w);
1174
void QWidgetPrivate::setUpdatesEnabled_helper(bool enable)
1178
if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled())
1179
return; // nothing we can do
1181
if (enable != q->testAttribute(Qt::WA_UpdatesDisabled))
1182
return; // nothing to do
1184
q->setAttribute(Qt::WA_UpdatesDisabled, !enable);
1188
Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceUpdatesDisabled : Qt::WA_UpdatesDisabled;
1189
for (int i = 0; i < children.size(); ++i) {
1190
QWidget *w = qobject_cast<QWidget *>(children.at(i));
1191
if (w && !w->testAttribute(attribute))
1192
w->d_func()->setUpdatesEnabled_helper(enable);
1196
void QWidgetPrivate::propagatePaletteChange()
1199
QEvent pc(QEvent::PaletteChange);
1200
QApplication::sendEvent(q, &pc);
1201
if(!children.isEmpty()) {
1202
for(int i = 0; i < children.size(); ++i) {
1203
QWidget *w = qobject_cast<QWidget*>(children.at(i));
1204
if (w && !w->isWindow())
1205
w->d_func()->resolvePalette();
1208
#if defined(QT3_SUPPORT)
1209
q->paletteChange(q->palette()); // compatibility
1215
Returns the widget's clipping rectangle.
1217
QRect QWidgetPrivate::clipRect() const
1220
const QWidget * w = q;
1221
if (!w->isVisible())
1223
QRect r = q->rect();
1229
&& w->parentWidget()) {
1232
w = w->parentWidget();
1233
r &= QRect(ox, oy, w->width(), w->height());
1238
bool QWidgetPrivate::isFullyOpaque() const
1241
if (q->testAttribute(Qt::WA_NoBackground) || q->testAttribute(Qt::WA_NoSystemBackground)
1242
|| q->isWindow() || q->windowType() == Qt::SubWindow)
1245
const QPalette &pal = q->palette();
1246
QPalette::ColorRole bg = q->backgroundRole();
1247
QBrush bgBrush = pal.brush(bg);
1248
QPalette::ColorRole bgrl = bg_role;
1249
return (bgBrush.style() != Qt::NoBrush && bgBrush.isOpaque()
1250
&& ((bgrl != QPalette::NoRole || (pal.resolve() & (1<<bg)))));
1254
Returns true if the widget's clipping region (excluding siblings) is
1255
complex; otherwise returns false.
1257
bool QWidgetPrivate::hasComplexClipRegion() const
1261
const QWidget * w = q;
1262
const QWidget *ignoreUpTo;
1268
&& w->parentWidget()) {
1272
w = w->parentWidget();
1273
r &= QRect(ox, oy, w->width(), w->height());
1276
while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo))
1278
for ( ; i < w->d_func()->children.size(); ++i) {
1279
if(QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) {
1280
if(sibling->isVisible() && !sibling->isWindow()) {
1281
QRect siblingRect(ox+sibling->x(), oy+sibling->y(),
1282
sibling->width(), sibling->height());
1283
if(siblingRect.intersects(q->rect()))
1294
\fn void QPixmap::fill(const QWidget *widget, const QPoint &offset)
1296
Fills the pixmap with the \a widget's background color or pixmap.
1298
The \a offset point is an offset in the widget.
1300
The point \a offset is a point in the widget's coordinate
1301
system. The pixmap's top-left pixel will be mapped to the point \a
1302
offset in the widget. This is significant if the widget has a
1303
background pixmap; otherwise the pixmap will simply be filled with
1304
the background color of the widget.
1307
void QPixmap::fill( const QWidget *widget, const QPoint &off )
1309
QPainter::setRedirected(widget, this, off);
1310
const_cast<QWidget *>(widget)->d_func()->composeBackground(widget->rect());
1311
QPainter::restoreRedirected(widget);
1316
This function is called when a widget is hidden or destroyed.
1317
It resets some application global pointers that should only refer active,
1321
void QWidgetPrivate::deactivateWidgetCleanup()
1324
// If this was the active application window, reset it
1325
if (qApp->activeWindow() == q)
1326
qApp->setActiveWindow(0);
1327
// If the is the active mouse press widget, reset it
1329
extern QPointer<QWidget> qt_button_down;
1331
extern QWidget *qt_button_down;
1333
if (q == qt_button_down)
1339
Returns a pointer to the widget with window identifer/handle \a
1342
The window identifier type depends on the underlying window
1343
system, see \c qwindowdefs.h for the actual definition. If there
1344
is no widget with this identifier, 0 is returned.
1347
QWidget *QWidget::find(WId id)
1349
return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0;
1355
\fn WId QWidget::winId() const
1357
Returns the window system identifier of the widget.
1359
Portable in principle, but if you use it you are probably about to
1360
do something non-portable. Be careful.
1367
Returns the GUI style for this widget
1369
\sa QWidget::setStyle(), QApplication::setStyle(), QApplication::style()
1372
QStyle *QWidget::style() const
1375
if (d->extra && d->extra->style)
1376
return d->extra->style;
1377
return qApp->style();
1381
Sets the widget's GUI style to \a style. Ownership of the style
1382
object is not transferred.
1384
If no style is set, the widget uses the application's style,
1385
QApplication::style() instead.
1387
Setting a widget's style has no effect on existing or future child
1390
\warning This function is particularly useful for demonstration
1391
purposes, where you want to show Qt's styling capabilities. Real
1392
applications should avoid it and use one consistent GUI style
1395
\sa style(), QStyle, QApplication::style(), QApplication::setStyle()
1398
void QWidget::setStyle(QStyle *style)
1401
QStyle *old = QWidget::style();
1403
d->extra->style = style;
1404
if (!(windowType() == Qt::Desktop) // (except desktop)
1405
&& d->polished) { // (and have been polished)
1406
old->unpolish(this);
1407
QWidget::style()->polish(this);
1409
QEvent e(QEvent::StyleChange);
1410
QApplication::sendEvent(this, &e);
1420
Sets the widget's GUI style to \a style using the QStyleFactory.
1422
QStyle* QWidget::setStyle(const QString &style)
1424
QStyle *s = QStyleFactory::create(style);
1431
\property QWidget::isWindow
1432
\brief whether the widget is an independent window
1434
A window is a widget that isn't visually the child of any other
1435
widget and that usually has a frame and a
1436
\l{QWidget::setWindowTitle()}{window title}.
1438
A window can have a \l{QWidget::parentWidget()}{parent widget}.
1439
It will then be grouped with its parent and deleted when the
1440
parent is deleted, minimized when the parent is minimized etc. If
1441
supported by the window manager, it will also have a common
1442
taskbar entry with its parent.
1444
QDialog and QMainWindow widgets are by default windows, even if a
1445
parent widget is specified in the constructor. This behavior is
1446
specified by the Qt::Window flag.
1448
\sa window(), isModal(), parentWidget()
1452
\property QWidget::modal
1453
\brief whether the widget is a modal widget
1455
This property only makes sense for windows. A modal widget
1456
prevents widgets in all other windows from getting any input.
1458
\sa isWindow(), QDialog
1462
\fn bool QWidget::underMouse() const
1464
Returns true if the widget is under the mouse cursor; otherwise
1467
This value is not updated properly during drag and drop
1470
\sa enterEvent(), leaveEvent()
1474
\property QWidget::minimized
1475
\brief whether this widget is minimized (iconified)
1477
This property is only relevant for windows.
1479
\sa showMinimized(), visible, show(), hide(), showNormal(), maximized
1481
bool QWidget::isMinimized() const
1482
{ return data->window_state & Qt::WindowMinimized; }
1485
Shows the widget minimized, as an icon.
1487
Calling this function only affects \l{isWindow()}{windows}.
1489
\sa showNormal(), showMaximized(), show(), hide(), isVisible(),
1492
void QWidget::showMinimized()
1494
bool isMin = isMinimized();
1495
if (isMin && isVisible()) return;
1500
QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
1504
setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized);
1509
\property QWidget::maximized
1510
\brief whether this widget is maximized
1512
This property is only relevant for windows.
1514
Note that due to limitations in some window-systems, this does not
1515
always report the expected results (e.g. if the user on X11
1516
maximizes the window via the window manager, Qt has no way of
1517
distinguishing this from any other resize). This is expected to
1518
improve as window manager protocols evolve.
1520
\sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized
1522
bool QWidget::isMaximized() const
1523
{ return data->window_state & Qt::WindowMaximized; }
1527
/*! Returns the current window state. The window state is a OR'ed
1528
combination of Qt::WindowState: \c Qt::WindowMinimized, \c
1529
Qt::WindowMaximized, \c Qt::WindowFullScreen and \c Qt::WindowActive.
1531
\sa Qt::WindowState setWindowState()
1533
Qt::WindowStates QWidget::windowState() const
1535
return (Qt::WindowStates)data->window_state;
1540
The function sets the window state without sending any events. It
1541
exists mainly to keep Q3Workspace working.
1543
void QWidget::overrideWindowState(Qt::WindowStates newstate)
1545
data->window_state = newstate;
1549
\fn void QWidget::setWindowState(Qt::WindowStates windowState)
1551
Sets the window state to \a windowState. The window state is a OR'ed
1552
combination of Qt::WindowState: \c Qt::WindowMinimized, \c
1553
Qt::WindowMaximized, \c Qt::WindowFullScreen and \c Qt::WindowActive.
1555
If the window is not visible (i.e. isVisible() returns false), the
1556
window state will take effect when show() is called. For visible
1557
windows, the change is immediate. For example, to toggle between
1558
full-screen and mormal mode, use the following code:
1561
w->setWindowState(w->windowState() ^ Qt::WindowFullScreen);
1564
In order to restore and activate a minimized window (while
1565
preserving its maximized and/or full-screen state), use the following:
1568
w->setWindowState(w->windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
1571
Note: On some window systems \c Qt::WindowActive is not immediate, and may be
1572
ignored in certain cases.
1574
\sa Qt::WindowState windowState()
1578
\property QWidget::fullScreen
1579
\brief whether the widget is full screen
1581
\sa windowState(), minimized, maximized
1583
bool QWidget::isFullScreen() const
1584
{ return data->window_state & Qt::WindowFullScreen; }
1587
Shows the widget in full-screen mode.
1589
Calling this function only affects windows.
1591
To return from full-screen mode, call showNormal().
1593
Full-screen mode works fine under Windows, but has certain
1594
problems under X. These problems are due to limitations of the
1595
ICCCM protocol that specifies the communication between X11
1596
clients and the window manager. ICCCM simply does not understand
1597
the concept of non-decorated full-screen windows. Therefore, the
1598
best we can do is to request a borderless window and place and
1599
resize it to fill the entire screen. Depending on the window
1600
manager, this may or may not work. The borderless window is
1601
requested using MOTIF hints, which are at least partially
1602
supported by virtually all modern window managers.
1604
An alternative would be to bypass the window manager entirely and
1605
create a window with the Qt::WX11BypassWM flag. This has other severe
1606
problems though, like totally broken keyboard focus and very
1607
strange effects on desktop changes or when the user raises other
1610
X11 window managers that follow modern post-ICCCM specifications
1611
support full-screen mode properly.
1613
\sa showNormal(), showMaximized(), show(), hide(), isVisible()
1615
void QWidget::showFullScreen()
1617
bool isFull = isFullScreen();
1618
if (isFull && isVisible())
1624
QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
1628
setWindowState(windowState() | Qt::WindowFullScreen);
1634
Shows the widget maximized.
1636
Calling this function only affects \l{isWindow()}{windows}.
1638
On X11, this function may not work properly with certain window
1639
managers. See \l{geometry.html}{Window Geometry} for an explanation.
1641
\sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()
1643
void QWidget::showMaximized()
1645
if (isMaximized() && isVisible() && !isMinimized())
1651
QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
1654
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowMaximized);
1659
Restores the widget after it has been maximized or minimized.
1661
Calling this function only affects \l{isWindow()}{windows}.
1663
\sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible()
1665
void QWidget::showNormal()
1670
QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
1673
setWindowState(Qt::WindowNoState);
1678
Returns true if this widget would become enabled if \a ancestor is
1679
enabled; otherwise returns false.
1683
This is the case if neither the widget itself nor every parent up
1684
to but excluding \a ancestor has been explicitly disabled.
1686
isEnabledTo(0) is equivalent to isEnabled().
1688
\sa setEnabled() enabled
1691
bool QWidget::isEnabledTo(QWidget* ancestor) const
1693
const QWidget * w = this;
1694
while (w && !w->testAttribute(Qt::WA_ForceDisabled)
1696
&& w->parentWidget()
1697
&& w->parentWidget() != ancestor)
1698
w = w->parentWidget();
1699
return !w->testAttribute(Qt::WA_ForceDisabled);
1703
Appends the action \a action to this widget's list of actions.
1705
All QWidgets have list of QActions, however they can be
1706
represented graphically in many different ways. The default use of
1707
the QAction list (as returned by actions()) is to create a context
1710
\sa removeAction() QMenu
1712
void QWidget::addAction(QAction *action)
1714
insertAction(0, action);
1718
Appends the actions \a actions to this widget's list of actions.
1720
\sa removeAction() QMenu addAction()
1722
void QWidget::addActions(QList<QAction*> actions)
1724
for(int i = 0; i < actions.count(); i++)
1725
insertAction(0, actions.at(i));
1729
Inserts the action \a action to this widget's list of actions,
1730
before the action \a before. It appends the action if \a before is 0 or
1731
\a before is not a valid action for this widget.
1735
void QWidget::insertAction(QAction *before, QAction *action)
1738
qWarning("Attempt to insert null action!");
1743
if(d->actions.contains(action))
1744
d->actions.removeAll(action);
1745
int pos = d->actions.indexOf(before);
1748
pos = d->actions.size();
1750
d->actions.insert(pos, action);
1752
QActionPrivate *apriv = action->d_func();
1753
apriv->widgets.append(this);
1755
QActionEvent e(QEvent::ActionAdded, action, before);
1756
QApplication::sendEvent(this, &e);
1760
Inserts the actions \a actions to this widget's list of actions,
1761
before the action \a before. It appends the action if \a before is 0 or
1762
\a before is not a valid action for this widget.
1764
\sa removeAction() QMenu insertAction()
1766
void QWidget::insertActions(QAction *before, QList<QAction*> actions)
1768
for(int i = 0; i < actions.count(); ++i)
1769
insertAction(before, actions.at(i));
1773
Removes the action \a action from this widget's list of actions.
1775
void QWidget::removeAction(QAction *action)
1782
QActionPrivate *apriv = action->d_func();
1783
apriv->widgets.removeAll(this);
1785
if (d->actions.removeAll(action)) {
1786
QActionEvent e(QEvent::ActionRemoved, action);
1787
QApplication::sendEvent(this, &e);
1792
Returns the (possibly empty) list of this widget's actions.
1794
QList<QAction*> QWidget::actions() const
1801
\fn bool QWidget::isEnabledToTLW() const
1804
This function is deprecated. It is equivalent to isEnabled()
1808
\property QWidget::enabled
1809
\brief whether the widget is enabled
1811
An enabled widget handles keyboard and mouse events; a disabled
1816
Some widgets display themselves differently when they are
1817
disabled. For example a button might draw its label grayed out. If
1818
your widget needs to know when it becomes enabled or disabled, you
1819
can use the changeEvent() with type QEvent::EnabledChange.
1821
Disabling a widget implicitly disables all its children. Enabling
1822
respectively enables all child widgets unless they have been
1823
explicitly disabled.
1825
\sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent()
1827
void QWidget::setEnabled(bool enable)
1830
setAttribute(Qt::WA_ForceDisabled, !enable);
1831
d->setEnabled_helper(enable);
1834
void QWidgetPrivate::setEnabled_helper(bool enable)
1838
if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled())
1839
return; // nothing we can do
1841
if (enable != q->testAttribute(Qt::WA_Disabled))
1842
return; // nothing to do
1844
q->setAttribute(Qt::WA_Disabled, !enable);
1845
updateSystemBackground();
1847
if (!enable && q->window()->focusWidget() == q) {
1848
bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled());
1849
if (!parentIsEnabled || !q->focusNextChild())
1853
Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceDisabled : Qt::WA_Disabled;
1854
for (int i = 0; i < children.size(); ++i) {
1855
QWidget *w = qobject_cast<QWidget *>(children.at(i));
1856
if (w && !w->testAttribute(attribute))
1857
w->d_func()->setEnabled_helper(enable);
1859
#if defined(Q_WS_X11)
1860
if (q->testAttribute(Qt::WA_SetCursor)) {
1861
// enforce the windows behavior of clearing the cursor on
1863
extern void qt_x11_enforce_cursor(QWidget * w); // defined in qwidget_x11.cpp
1864
qt_x11_enforce_cursor(q);
1868
QWinInputContext::enable(q, q->testAttribute(Qt::WA_InputMethodEnabled) && enable);
1870
QEvent e(QEvent::EnabledChange);
1871
QApplication::sendEvent(q, &e);
1873
q->enabledChange(!enable); // compatibility
1878
\property QWidget::acceptDrops
1879
\brief whether drop events are enabled for this widget
1881
Setting this property to true announces to the system that this
1882
widget \e may be able to accept drop events.
1884
If the widget is the desktop (QWidget::(windowType() == Qt::Desktop)), this may
1885
fail if another application is using the desktop; you can call
1886
acceptDrops() to test if this occurs.
1889
Do not modify this property in a Drag&Drop event handler.
1891
bool QWidget::acceptDrops() const
1893
return testAttribute(Qt::WA_AcceptDrops);
1896
void QWidget::setAcceptDrops(bool on)
1898
setAttribute(Qt::WA_ForceAcceptDrops, on);
1899
d_func()->setAcceptDrops_helper(on);
1902
void QWidgetPrivate::setAcceptDrops_helper(bool on)
1906
if (!on && !q->isWindow() && q->parentWidget() && q->parentWidget()->acceptDrops())
1907
return; // nothing we can do
1909
if (on == q->testAttribute(Qt::WA_AcceptDrops))
1910
return; // nothing to do
1912
if (!setAcceptDrops_sys(on))
1913
return; // nothing was changed
1915
q->setAttribute(Qt::WA_AcceptDrops, on);
1917
Qt::WidgetAttribute attribute = on ? Qt::WA_AcceptDrops : Qt::WA_ForceAcceptDrops;
1918
for (int i = 0; i < children.size(); ++i) {
1919
QWidget *w = qobject_cast<QWidget *>(children.at(i));
1920
if (w && !w->testAttribute(attribute))
1921
w->d_func()->setAcceptDrops_helper(on);
1926
\fn void QWidget::enabledChange(bool)
1933
\fn void QWidget::paletteChange(const QPalette &)
1940
\fn void QWidget::fontChange(const QFont &)
1947
\fn void QWidget::windowActivationChange(bool)
1954
\fn void QWidget::languageChange()
1961
\fn void QWidget::styleChange(QStyle& style)
1968
Disables widget input events if \a disable is true; otherwise
1969
enables input events.
1971
See the \l enabled documentation for more information.
1973
\sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent()
1975
void QWidget::setDisabled(bool disable)
1977
setEnabled(!disable);
1981
\property QWidget::frameGeometry
1982
\brief geometry of the widget relative to its parent including any
1985
See the \link geometry.html Window Geometry documentation\endlink
1986
for an overview of geometry issues with windows.
1988
\sa geometry() x() y() pos()
1990
QRect QWidget::frameGeometry() const
1993
if (isWindow() && ! (windowType() == Qt::Popup)) {
1994
if (data->fstrut_dirty)
1995
d->updateFrameStrut();
1996
QTLWExtra *top = d->topData();
1997
return QRect(data->crect.x() - top->fleft,
1998
data->crect.y() - top->ftop,
1999
data->crect.width() + top->fleft + top->fright,
2000
data->crect.height() + top->ftop + top->fbottom);
2006
\property QWidget::x
2008
\brief the x coordinate of the widget relative to its parent including
2011
See the \link geometry.html Window Geometry documentation\endlink
2012
for an overview of window geometry.
2014
\sa frameGeometry, y, pos
2016
int QWidget::x() const
2019
if (isWindow() && ! (windowType() == Qt::Popup)) {
2020
if (data->fstrut_dirty)
2021
d->updateFrameStrut();
2022
return data->crect.x() - d->topData()->fleft;
2024
return data->crect.x();
2028
\property QWidget::y
2029
\brief the y coordinate of the widget relative to its parent and
2030
including any window frame
2032
See the \link geometry.html Window Geometry documentation\endlink
2033
for an overview of window geometry.
2035
\sa frameGeometry, x, pos
2037
int QWidget::y() const
2040
if (isWindow() && ! (windowType() == Qt::Popup)) {
2041
if (data->fstrut_dirty)
2042
d->updateFrameStrut();
2043
return data->crect.y() - d->topData()->ftop;
2045
return data->crect.y();
2049
\property QWidget::pos
2050
\brief the position of the widget within its parent widget
2052
If the widget is a window, the position is that of the widget on
2053
the desktop, including its frame.
2055
When changing the position, the widget, if visible, receives a
2056
move event (moveEvent()) immediately. If the widget is not
2057
currently visible, it is guaranteed to receive an event before it
2060
move() is virtual, and all other overloaded move() implementations
2063
\warning Calling move() or setGeometry() inside moveEvent() can
2064
lead to infinite recursion.
2066
See the \link geometry.html Window Geometry documentation\endlink
2067
for an overview of window geometry.
2069
\sa frameGeometry, size x(), y()
2071
QPoint QWidget::pos() const
2074
if (isWindow() && ! (windowType() == Qt::Popup)) {
2075
if (data->fstrut_dirty)
2076
d->updateFrameStrut();
2077
QTLWExtra *top = d->topData();
2078
return QPoint(data->crect.x() - top->fleft, data->crect.y() - top->ftop);
2080
return data->crect.topLeft();
2084
\property QWidget::geometry
2085
\brief the geometry of the widget relative to its parent and
2086
excluding the window frame
2088
When changing the geometry, the widget, if visible, receives a
2089
move event (moveEvent()) and/or a resize event (resizeEvent())
2090
immediately. If the widget is not currently visible, it is
2091
guaranteed to receive appropriate events before it is shown.
2093
The size component is adjusted if it lies outside the range
2094
defined by minimumSize() and maximumSize().
2096
\warning Calling setGeometry() inside resizeEvent() or moveEvent()
2097
can lead to infinite recursion.
2099
See the \link geometry.html Window Geometry documentation\endlink
2100
for an overview of window geometry.
2102
\sa frameGeometry(), rect(), move(), resize(), moveEvent(),
2103
resizeEvent(), minimumSize(), maximumSize()
2107
\property QWidget::normalGeometry
2108
\brief the geometry a toplevel widget has when it is not maximized or fullscreen
2110
For child widgets this property always holds an empty rect.
2112
\sa QWidget::windowState(), QWidget::geometry
2116
\property QWidget::size
2117
\brief the size of the widget excluding any window frame
2119
If the widget is visible when it is being resized, it receives a resize event
2120
(resizeEvent()) immediately. If the widget is not currently
2121
visible, it is guaranteed to receive an event before it is shown.
2123
The size is adjusted if it lies outside the range defined by
2124
minimumSize() and maximumSize(). For windows, the minimum size
2125
is always at least QSize(1, 1), and it might be larger, depending on
2128
\warning Calling resize() or setGeometry() inside resizeEvent() can
2129
lead to infinite recursion.
2131
\sa pos, geometry, minimumSize, maximumSize, resizeEvent()
2135
\property QWidget::width
2136
\brief the width of the widget excluding any window frame
2138
See the \link geometry.html Window Geometry documentation\endlink
2139
for an overview of window geometry.
2141
\sa geometry, height, size
2145
\property QWidget::height
2146
\brief the height of the widget excluding any window frame
2148
See the \link geometry.html Window Geometry documentation\endlink
2149
for an overview of window geometry.
2151
\sa geometry, width, size
2155
\property QWidget::rect
2156
\brief the internal geometry of the widget excluding any window
2159
The rect property equals QRect(0, 0, width(), height()).
2161
See the \link geometry.html Window Geometry documentation\endlink
2162
for an overview of window geometry.
2168
QRect QWidget::normalGeometry() const
2171
if (!d->extra || !d->extra->topextra)
2174
if (!isMaximized() && !isFullScreen())
2177
return d->topData()->normalGeometry;
2182
\property QWidget::childrenRect
2183
\brief the bounding rectangle of the widget's children
2185
Hidden children are excluded.
2187
\sa childrenRegion() geometry()
2190
QRect QWidget::childrenRect() const
2193
QRect r(0, 0, 0, 0);
2194
for (int i = 0; i < d->children.size(); ++i) {
2195
QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
2196
if (w && !w->isWindow() && !w->isHidden())
2203
\property QWidget::childrenRegion
2204
\brief the combined region occupied by the widget's children
2206
Hidden children are excluded.
2208
\sa childrenRect() geometry()
2211
QRegion QWidget::childrenRegion() const
2215
for (int i = 0; i < d->children.size(); ++i) {
2216
QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
2217
if (w && !w->isWindow() && !w->isHidden()) {
2218
QRegion mask = w->mask();
2230
\property QWidget::minimumSize
2231
\brief the widget's minimum size
2233
The widget cannot be resized to a smaller size than the minimum
2234
widget size. The widget's size is forced to the minimum size if
2235
the current size is smaller.
2237
The minimum size set by this function will override the minimum size defined by QLayout.
2239
\sa minimumWidth, minimumHeight, maximumSize, sizeIncrement
2242
QSize QWidget::minimumSize() const
2245
return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0);
2249
\property QWidget::maximumSize
2250
\brief the widget's maximum size
2252
The widget cannot be resized to a larger size than the maximum
2255
\sa maximumWidth, maximumHeight, minimumSize, sizeIncrement
2258
QSize QWidget::maximumSize() const
2261
return d->extra ? QSize(d->extra->maxw, d->extra->maxh)
2262
: QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
2267
\property QWidget::minimumWidth
2268
\brief the widget's minimum width
2270
This property corresponds to minimumSize().width().
2272
\sa minimumSize, minimumHeight
2276
\property QWidget::minimumHeight
2277
\brief the widget's minimum height
2279
This property corresponds to minimumSize().height().
2281
\sa minimumSize, minimumWidth
2285
\property QWidget::maximumWidth
2286
\brief the widget's maximum width
2288
This property corresponds to maximumSize().width().
2290
\sa maximumSize, maximumHeight
2294
\property QWidget::maximumHeight
2295
\brief the widget's maximum height
2297
This property corresponds to maximumSize().height().
2299
\sa maximumSize, maximumWidth
2303
\property QWidget::sizeIncrement
2304
\brief the size increment of the widget
2306
When the user resizes the window, the size will move in steps of
2307
sizeIncrement().width() pixels horizontally and
2308
sizeIncrement.height() pixels vertically, with baseSize() as the
2309
basis. Preferred widget sizes are for non-negative integers \e i
2312
width = baseSize().width() + i * sizeIncrement().width();
2313
height = baseSize().height() + j * sizeIncrement().height();
2316
Note that while you can set the size increment for all widgets, it
2317
only affects windows.
2319
\warning The size increment has no effect under Windows, and may
2320
be disregarded by the window manager on X.
2322
\sa size, minimumSize, maximumSize
2324
QSize QWidget::sizeIncrement() const
2327
return (d->extra && d->extra->topextra)
2328
? QSize(d->extra->topextra->incw, d->extra->topextra->inch)
2333
\property QWidget::baseSize
2334
\brief the base size of the widget
2336
The base size is used to calculate a proper widget size if the
2337
widget defines sizeIncrement().
2339
\sa setSizeIncrement()
2342
QSize QWidget::baseSize() const
2345
return (d->extra != 0 && d->extra->topextra != 0)
2346
? QSize(d->extra->topextra->basew, d->extra->topextra->baseh)
2351
extern QRect qt_maxWindowRect;
2357
This function corresponds to setMinimumSize(QSize(minw, minh)).
2358
Sets the minimum width to \a minw and the minimum height to \a
2362
void QWidget::setMinimumSize(int minw, int minh)
2366
if (!qt_maxWindowRect.isEmpty()) {
2367
// ### This is really just a work-around. Layout shouldn't be asking
2368
// for minimum sizes bigger than the screen.
2369
if (minw > qt_maxWindowRect.width())
2370
minw = qt_maxWindowRect.width();
2371
if (minh > qt_maxWindowRect.height())
2372
minh = qt_maxWindowRect.height();
2375
if (minw < 0 || minh < 0)
2376
qWarning("QWidget::setMinimumSize: The smallest allowed size is (0,0)");
2378
if (d->extra->minw == minw && d->extra->minh == minh)
2380
d->extra->minw = minw;
2381
d->extra->minh = minh;
2382
d->extra->explicitMinSize = (minw ? Qt::Horizontal : 0) | (minh ? Qt::Vertical : 0);
2384
if (minw > width() || minh > height()) {
2385
bool resized = testAttribute(Qt::WA_Resized);
2386
bool maximized = isMaximized();
2387
resize(qMax(minw,width()), qMax(minh,height()));
2388
setAttribute(Qt::WA_Resized, resized); //not a user resize
2390
data->window_state = data->window_state | Qt::WindowMaximized;
2393
d->setConstraints_sys();
2400
This function corresponds to setMaximumSize(QSize(\a maxw, \a
2401
maxh)). Sets the maximum width to \a maxw and the maximum height
2404
void QWidget::setMaximumSize(int maxw, int maxh)
2407
if (maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX) {
2408
qWarning("QWidget::setMaximumSize: (%s/%s) "
2409
"The largest allowed size is (%d,%d)",
2410
objectName().toLocal8Bit().data(), metaObject()->className(), QWIDGETSIZE_MAX,
2412
maxw = qMin<int>(maxw, QWIDGETSIZE_MAX);
2413
maxh = qMin<int>(maxh, QWIDGETSIZE_MAX);
2415
if (maxw < 0 || maxh < 0) {
2416
qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
2418
objectName().toLocal8Bit().data(), metaObject()->className(), maxw, maxh);
2419
maxw = qMax(maxw, 0);
2420
maxh = qMax(maxh, 0);
2423
if (d->extra->maxw == maxw && d->extra->maxh == maxh)
2425
d->extra->maxw = maxw;
2426
d->extra->maxh = maxh;
2427
if (maxw < width() || maxh < height()) {
2428
bool resized = testAttribute(Qt::WA_Resized);
2429
resize(qMin(maxw,width()), qMin(maxh,height()));
2430
setAttribute(Qt::WA_Resized, resized); //not a user resize
2433
d->setConstraints_sys();
2440
Sets the x (width) size increment to \a w and the y (height) size
2443
void QWidget::setSizeIncrement(int w, int h)
2447
QTLWExtra* x = d->topData();
2448
if (x->incw == w && x->inch == h)
2453
d->setConstraints_sys();
2459
This corresponds to setBaseSize(QSize(\a basew, \a baseh)). Sets
2460
the widgets base size to width \a basew and height \a baseh.
2462
void QWidget::setBaseSize(int basew, int baseh)
2466
QTLWExtra* x = d->topData();
2467
if (x->basew == basew && x->baseh == baseh)
2472
d->setConstraints_sys();
2476
Sets both the minimum and maximum sizes of the widget to \a s,
2477
thereby preventing it from ever growing or shrinking.
2479
This will override the default size constraints set by QLayout.
2481
Alternatively, if you want the widget to have a
2482
fixed size based on its contents, you can call
2483
QLayout::setSizeConstraint(QLayout::SetFixedSize);
2485
\sa maximumSize, minimumSize
2488
void QWidget::setFixedSize(const QSize & s)
2497
\fn void QWidget::setFixedSize(int w, int h)
2500
Sets the width of the widget to \a w and the height to \a h.
2503
void QWidget::setFixedSize(int w, int h)
2505
setMinimumSize(w, h);
2506
setMaximumSize(w, h);
2510
void QWidget::setMinimumWidth(int w)
2514
uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0);
2515
setMinimumSize(w, minimumSize().height());
2516
d->extra->explicitMinSize = expl;
2519
void QWidget::setMinimumHeight(int h)
2523
uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0);
2524
setMinimumSize(minimumSize().width(), h);
2525
d->extra->explicitMinSize = expl;
2528
void QWidget::setMaximumWidth(int w)
2530
setMaximumSize(w, maximumSize().height());
2533
void QWidget::setMaximumHeight(int h)
2535
setMaximumSize(maximumSize().width(), h);
2539
Sets both the minimum and maximum width of the widget to \a w
2540
without changing the heights. Provided for convenience.
2542
\sa sizeHint() minimumSize() maximumSize() setFixedSize()
2545
void QWidget::setFixedWidth(int w)
2549
uint expl = d->extra->explicitMinSize | Qt::Horizontal;
2550
setMinimumSize(w, minimumSize().height());
2551
setMaximumSize(w, maximumSize().height());
2552
d->extra->explicitMinSize = expl;
2557
Sets both the minimum and maximum heights of the widget to \a h
2558
without changing the widths. Provided for convenience.
2560
\sa sizeHint() minimumSize() maximumSize() setFixedSize()
2563
void QWidget::setFixedHeight(int h)
2567
uint expl = d->extra->explicitMinSize | Qt::Vertical;
2568
setMinimumSize(minimumSize().width(), h);
2569
setMaximumSize(maximumSize().width(), h);
2570
d->extra->explicitMinSize = expl;
2575
Translates the widget coordinate \a pos to the coordinate system
2576
of \a parent. The \a parent must not be 0 and must be a parent
2577
of the calling widget.
2579
\sa mapFrom() mapToParent() mapToGlobal() underMouse()
2582
QPoint QWidget::mapTo(QWidget * parent, const QPoint & pos) const
2586
const QWidget * w = this;
2587
while (w != parent) {
2588
p = w->mapToParent(p);
2589
w = w->parentWidget();
2597
Translates the widget coordinate \a pos from the coordinate system
2598
of \a parent to this widget's coordinate system. The \a parent
2599
must not be 0 and must be a parent of the calling widget.
2601
\sa mapTo() mapFromParent() mapFromGlobal() underMouse()
2604
QPoint QWidget::mapFrom(QWidget * parent, const QPoint & pos) const
2608
const QWidget * w = this;
2609
while (w != parent) {
2610
p = w->mapFromParent(p);
2611
w = w->parentWidget();
2619
Translates the widget coordinate \a pos to a coordinate in the
2622
Same as mapToGlobal() if the widget has no parent.
2624
\sa mapFromParent() mapTo() mapToGlobal() underMouse()
2627
QPoint QWidget::mapToParent(const QPoint &pos) const
2629
return pos + data->crect.topLeft();
2633
Translates the parent widget coordinate \a pos to widget
2636
Same as mapFromGlobal() if the widget has no parent.
2638
\sa mapToParent() mapFrom() mapFromGlobal() underMouse()
2641
QPoint QWidget::mapFromParent(const QPoint &pos) const
2643
return pos - data->crect.topLeft();
2648
Returns the window for this widget, i.e. the next ancestor widget
2649
that has (or could have) a window-system frame.
2651
If the widget is a window, the widget itself is returned.
2653
Typical usage is changing the window title:
2656
aWidget->window()->setWindowTitle("New Window Title");
2662
QWidget *QWidget::window() const
2664
QWidget *w = (QWidget *)this;
2665
QWidget *p = w->parentWidget();
2666
while (!w->isWindow() && p) {
2668
p = p->parentWidget();
2673
/*! \fn QWidget *QWidget::topLevelWidget() const
2676
Use window() instead.
2681
Returns the color role used for painting the widget's background.
2683
Use QPalette(backgroundRole(()) instead.
2685
Qt::BackgroundMode QWidget::backgroundMode() const
2687
if (testAttribute(Qt::WA_NoSystemBackground))
2688
return Qt::NoBackground;
2689
switch(backgroundRole()) {
2690
case QPalette::Foreground:
2691
return Qt::PaletteForeground;
2692
case QPalette::Button:
2693
return Qt::PaletteButton;
2694
case QPalette::Light:
2695
return Qt::PaletteLight;
2696
case QPalette::Midlight:
2697
return Qt::PaletteMidlight;
2698
case QPalette::Dark:
2699
return Qt::PaletteDark;
2701
return Qt::PaletteMid;
2702
case QPalette::Text:
2703
return Qt::PaletteText;
2704
case QPalette::BrightText:
2705
return Qt::PaletteBrightText;
2706
case QPalette::Base:
2707
return Qt::PaletteBase;
2708
case QPalette::Background:
2709
return Qt::PaletteBackground;
2710
case QPalette::Shadow:
2711
return Qt::PaletteShadow;
2712
case QPalette::Highlight:
2713
return Qt::PaletteHighlight;
2714
case QPalette::HighlightedText:
2715
return Qt::PaletteHighlightedText;
2716
case QPalette::ButtonText:
2717
return Qt::PaletteButtonText;
2718
case QPalette::Link:
2719
return Qt::PaletteLink;
2720
case QPalette::LinkVisited:
2721
return Qt::PaletteLinkVisited;
2725
return Qt::NoBackground;
2729
\fn void QWidget::setBackgroundMode(Qt::BackgroundMode
2730
widgetBackground, Qt::BackgroundMode paletteBackground)
2732
Sets the color role used for painting the widget's background to
2733
background mode \a widgetBackground. The \a paletteBackground mode
2734
parameter is ignored.
2736
void QWidget::setBackgroundMode(Qt::BackgroundMode m, Qt::BackgroundMode)
2739
if(m == Qt::NoBackground) {
2740
setAttribute(Qt::WA_NoSystemBackground, true);
2743
setAttribute(Qt::WA_NoSystemBackground, false);
2744
d->fg_role = QPalette::NoRole;
2745
QPalette::ColorRole role = d->bg_role;
2747
case Qt::FixedColor:
2748
case Qt::FixedPixmap:
2750
case Qt::PaletteForeground:
2751
role = QPalette::Foreground;
2753
case Qt::PaletteButton:
2754
role = QPalette::Button;
2756
case Qt::PaletteLight:
2757
role = QPalette::Light;
2759
case Qt::PaletteMidlight:
2760
role = QPalette::Midlight;
2762
case Qt::PaletteDark:
2763
role = QPalette::Dark;
2765
case Qt::PaletteMid:
2766
role = QPalette::Mid;
2768
case Qt::PaletteText:
2769
role = QPalette::Text;
2771
case Qt::PaletteBrightText:
2772
role = QPalette::BrightText;
2774
case Qt::PaletteBase:
2775
role = QPalette::Base;
2777
case Qt::PaletteBackground:
2778
role = QPalette::Background;
2780
case Qt::PaletteShadow:
2781
role = QPalette::Shadow;
2783
case Qt::PaletteHighlight:
2784
role = QPalette::Highlight;
2786
case Qt::PaletteHighlightedText:
2787
role = QPalette::HighlightedText;
2789
case Qt::PaletteButtonText:
2790
role = QPalette::ButtonText;
2792
case Qt::PaletteLink:
2793
role = QPalette::Link;
2795
case Qt::PaletteLinkVisited:
2796
role = QPalette::LinkVisited;
2798
case Qt::X11ParentRelative:
2799
d->fg_role = role = QPalette::NoRole;
2803
setBackgroundRole(role);
2807
The widget mapper is no longer part of the public API.
2809
QT3_SUPPORT QWidgetMapper *QWidget::wmapper() { return QWidgetPrivate::mapper; }
2815
Returns the background role of the widget.
2817
The background role defines the brush from the widget's \l palette that
2818
is used to render the background.
2820
If no explicit background role is set, the widget inherts its parent
2821
widget's background role.
2823
\sa setBackgroundRole(), foregroundRole()
2825
QPalette::ColorRole QWidget::backgroundRole() const
2828
const QWidget *w = this;
2830
QPalette::ColorRole role = w->d_func()->bg_role;
2831
if (role != QPalette::NoRole)
2833
if (w->isWindow() || w->windowType() == Qt::SubWindow)
2835
w = w->parentWidget();
2837
return QPalette::Background;
2841
Sets the background role of the widget to \a role.
2843
The background role defines the brush from the widget's \l palette that
2844
is used to render the background.
2846
If \a role is \c QPalette::NoRole, then the widget inherits its
2847
parent's background role.
2849
\sa backgroundRole(), foregroundRole()
2852
void QWidget::setBackgroundRole(QPalette::ColorRole role)
2856
d->updateSystemBackground();
2857
d->propagatePaletteChange();
2861
Returns the foreground role.
2863
The foreground role defines the color from the widget's \l palette that
2864
is used to draw the foreground.
2866
If no explicit foreground role is set, the function returns a role
2867
that contrasts with the background role.
2869
\sa setForegroundRole(), backgroundRole()
2871
QPalette::ColorRole QWidget::foregroundRole() const
2874
QPalette::ColorRole rl = QPalette::ColorRole(d->fg_role);
2875
if (rl != QPalette::NoRole)
2877
QPalette::ColorRole role = QPalette::Foreground;
2878
switch (backgroundRole()) {
2879
case QPalette::Button:
2880
role = QPalette::ButtonText;
2882
case QPalette::Base:
2883
role = QPalette::Text;
2885
case QPalette::Dark:
2886
case QPalette::Shadow:
2887
role = QPalette::Light;
2889
case QPalette::Highlight:
2890
role = QPalette::HighlightedText;
2899
Sets the foreground role of the widget to \a role.
2901
The foreground role defines the color from the widget's \l palette that
2902
is used to draw the foreground.
2904
If \a role is \c QPalette::NoRole, the widget uses a foreground role
2905
that contrasts with the background role.
2907
\sa foregroundRole(), backgroundRole()
2909
void QWidget::setForegroundRole(QPalette::ColorRole role)
2913
d->updateSystemBackground();
2914
d->propagatePaletteChange();
2918
\property QWidget::palette
2919
\brief the widget's palette
2921
As long as no special palette has been set, this is either a
2922
special palette for the widget class, the parent's palette or (if
2923
this widget is a top level widget), the default application
2926
\sa QApplication::palette()
2928
const QPalette &QWidget::palette() const
2931
data->pal.setCurrentColorGroup(QPalette::Disabled);
2932
} else if (!isVisible() || isActiveWindow()) {
2933
data->pal.setCurrentColorGroup(QPalette::Active);
2936
extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp
2937
if (qt_mac_can_clickThrough(this))
2938
data->pal.setCurrentColorGroup(QPalette::Active);
2941
data->pal.setCurrentColorGroup(QPalette::Inactive);
2946
void QWidget::setPalette(const QPalette &palette)
2949
setAttribute(Qt::WA_SetPalette, palette.resolve() != 0);
2950
d->setPalette_helper(palette.resolve(qt_naturalWidgetPalette(this)));
2953
void QWidgetPrivate::resolvePalette()
2956
setPalette_helper(data.pal.resolve(qt_naturalWidgetPalette(q)));
2959
void QWidgetPrivate::setPalette_helper(const QPalette &palette)
2961
if (data.pal == palette && data.pal.resolve() == palette.resolve())
2964
updateSystemBackground();
2965
propagatePaletteChange();
2970
\property QWidget::font
2971
\brief the font currently set for the widget
2973
The fontInfo() function reports the actual font that is being used
2976
As long as no special font has been set, or after setFont(QFont())
2977
is called, this is either a special font for the widget class, the
2978
parent's font or (if this widget is a top level widget), the
2979
default application font.
2981
This code fragment sets a 12 point helvetica bold font:
2983
QFont f("Helvetica", 12, QFont::Bold);
2987
In addition to setting the font, setFont() informs all children
2990
\sa fontInfo() fontMetrics()
2993
void QWidget::setFont(const QFont &font)
2996
setAttribute(Qt::WA_SetFont, font.resolve() != 0);
2997
d->setFont_helper(font);
3000
void QWidgetPrivate::resolveFont()
3003
setFont_helper(data.fnt.resolve(qt_naturalWidgetFont(q)));
3006
void QWidgetPrivate::setFont_helper(const QFont &font)
3008
if (data.fnt == font && data.fnt.resolve() == font.resolve())
3013
QFont old = data.fnt;
3016
#if defined(Q_WS_X11)
3017
// make sure the font set on this widget is associated with the correct screen
3018
data.fnt.x11SetScreen(xinfo.screen());
3020
for (int i = 0; i < children.size(); ++i) {
3021
QWidget *w = qobject_cast<QWidget*>(children.at(i));
3022
if (w && !w->isWindow())
3023
w->d_func()->resolveFont();
3025
QEvent e(QEvent::FontChange);
3026
QApplication::sendEvent(q, &e);
3032
void QWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction)
3036
if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft))
3038
q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));
3039
if (!children.isEmpty()) {
3040
for (int i = 0; i < children.size(); ++i) {
3041
QWidget *w = qobject_cast<QWidget*>(children.at(i));
3042
if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection))
3043
w->d_func()->setLayoutDirection_helper(direction);
3046
QEvent e(QEvent::LayoutDirectionChange);
3047
QApplication::sendEvent(q, &e);
3050
void QWidgetPrivate::resolveLayoutDirection()
3053
if (!q->testAttribute(Qt::WA_SetLayoutDirection))
3054
setLayoutDirection_helper(q->isWindow() ? QApplication::layoutDirection() : q->parentWidget()->layoutDirection());
3057
/*!\property QWidget::layoutDirection
3059
\brief the layout direction for this widget
3061
\sa QApplication::layoutDirection
3063
void QWidget::setLayoutDirection(Qt::LayoutDirection direction)
3067
setAttribute(Qt::WA_SetLayoutDirection);
3068
d->setLayoutDirection_helper(direction);
3071
Qt::LayoutDirection QWidget::layoutDirection() const
3073
return testAttribute(Qt::WA_RightToLeft) ? Qt::RightToLeft : Qt::LeftToRight;
3076
void QWidget::unsetLayoutDirection()
3079
setAttribute(Qt::WA_SetLayoutDirection, false);
3080
d->resolveLayoutDirection();
3084
\fn QFontMetrics QWidget::fontMetrics() const
3086
Returns the font metrics for the widget's current font.
3087
Equivalent to QFontMetrics(widget->font()).
3089
\sa font(), fontInfo(), setFont()
3093
\fn QFontInfo QWidget::fontInfo() const
3095
Returns the font info for the widget's current font.
3096
Equivalent to QFontInto(widget->font()).
3098
\sa font(), fontMetrics(), setFont()
3103
\property QWidget::cursor
3104
\brief the cursor shape for this widget
3106
The mouse cursor will assume this shape when it's over this
3107
widget. See the \link Qt::CursorShape list of predefined cursor
3108
objects\endlink for a range of useful shapes.
3110
An editor widget might use an I-beam cursor:
3112
setCursor(Qt::IBeamCursor);
3115
If no cursor has been set, or after a call to unsetCursor(), the
3116
parent's cursor is used. The function unsetCursor() has no effect
3119
\sa QApplication::setOverrideCursor()
3122
#ifndef QT_NO_CURSOR
3123
QCursor QWidget::cursor() const
3126
if (testAttribute(Qt::WA_SetCursor))
3127
return (d->extra && d->extra->curs)
3129
: QCursor(Qt::ArrowCursor);
3130
if (isWindow() || !parentWidget())
3131
return QCursor(Qt::ArrowCursor);
3132
return parentWidget()->cursor();
3136
\property QWidget::windowTitle
3137
\brief the window title (caption)
3139
This property only makes sense for windows. If no
3140
caption has been set, the title is an empty string.
3142
If you use the \l windowModified mechanism, the window title must
3143
contain a "[*]" placeholder, which indicates where the '*' should
3144
appear. Normally, it should appear right after the file name
3145
(e.g., "document1.txt[*] - Text Editor"). If the \l
3146
windowModified property is false (the default), the placeholder
3149
\sa windowIcon, windowIconText, windowModified
3151
QString QWidget::windowTitle() const
3154
return d->extra && d->extra->topextra
3155
? d->extra->topextra->caption
3159
QString qt_setWindowTitle_helperHelper(const QString &title, QWidget *widget)
3164
extern QString qt_eval_adapt_window_title(const QString &title);
3165
QString cap = qt_eval_adapt_window_title(title);
3167
QString cap = title;
3170
QString placeHolder(QLatin1String("[*]"));
3172
int index = cap.indexOf(placeHolder);
3174
while (index != -1) {
3175
index += placeHolder.length();
3177
while (cap.indexOf(placeHolder, index) == index) {
3179
index += placeHolder.length();
3182
if (count%2) { // odd number of [*] -> replace last one
3183
int lastIndex = cap.lastIndexOf(placeHolder, index - 1);
3184
if (widget->isWindowModified()
3185
&& widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget))
3186
cap.replace(lastIndex, 3, QWidget::tr("*"));
3188
cap.replace(lastIndex, 3, QLatin1String(""));
3191
index = cap.indexOf(placeHolder, index);
3194
cap.replace(QLatin1String("[*][*]"), QLatin1String("[*]"));
3199
#ifndef QT_NO_WIDGET_TOPEXTRA
3200
void QWidgetPrivate::setWindowTitle_helper(const QString &title)
3203
setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q));
3207
void QWidgetPrivate::setWindowIconText_helper(const QString &title)
3210
setWindowIconText_sys(qt_setWindowTitle_helperHelper(title, q));
3213
void QWidget::setWindowIconText(const QString &iconText)
3215
if (QWidget::windowIconText() == iconText)
3219
d->topData()->iconText = iconText;
3220
d->setWindowIconText_helper(iconText);
3222
QEvent e(QEvent::IconTextChange);
3223
QApplication::sendEvent(this, &e);
3226
void QWidget::setWindowTitle(const QString &title)
3228
if (QWidget::windowTitle() == title)
3232
#ifndef QT_NO_WIDGET_TOPEXTRA
3233
d->topData()->caption = title;
3234
d->setWindowTitle_helper(title);
3237
QEvent e(QEvent::WindowTitleChange);
3238
QApplication::sendEvent(this, &e);
3242
\property QWidget::windowIcon
3243
\brief the widget's icon
3245
This property only makes sense for windows. If no icon
3246
has been set, windowIcon() returns the application icon
3247
(QApplication::windowIcon()).
3249
\sa windowIconText, windowTitle
3251
QIcon QWidget::windowIcon() const
3253
const QWidget *w = this;
3255
const QWidgetPrivate *d = w->d_func();
3256
if (d->extra && d->extra->topextra && d->extra->topextra->icon)
3257
return *d->extra->topextra->icon;
3258
w = w->parentWidget();
3260
return qApp->windowIcon();
3263
void QWidget::setWindowIcon(const QIcon &icon)
3267
setAttribute(Qt::WA_SetWindowIcon, !icon.isNull());
3270
if (!d->extra->topextra->icon)
3271
d->extra->topextra->icon = new QIcon();
3272
*d->extra->topextra->icon = icon;
3274
delete d->extra->topextra->iconPixmap;
3275
d->extra->topextra->iconPixmap = 0;
3277
d->setWindowIcon_sys();
3278
QEvent e(QEvent::WindowIconChange);
3279
QApplication::sendEvent(this, &e);
3284
\property QWidget::windowIconText
3285
\brief the widget's icon text
3287
This property only makes sense for windows. If no icon
3288
text has been set, this functions returns an empty string.
3290
\sa windowIcon, windowTitle
3293
QString QWidget::windowIconText() const
3296
return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString();
3300
Returns the window's role, or an empty string.
3302
\sa windowIcon, windowTitle
3305
QString QWidget::windowRole() const
3308
return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString();
3312
Sets the window's role to \a role. This only makes sense for
3315
void QWidget::setWindowRole(const QString &role)
3317
#if defined(Q_WS_X11)
3319
d->topData()->role = role;
3320
d->setWindowRole(role.toUtf8().constData());
3327
\property QWidget::mouseTracking
3328
\brief whether mouse tracking is enabled for the widget
3330
If mouse tracking is disabled (the default), the widget only
3331
receives mouse move events when at least one mouse button is
3332
pressed while the mouse is being moved.
3334
If mouse tracking is enabled, the widget receives mouse move
3335
events even if no buttons are pressed.
3337
\sa mouseMoveEvent()
3342
Sets the widget's focus proxy to widget \a w. If \a w is 0, the
3343
function resets this widget to have no focus proxy.
3345
Some widgets can "have focus", but create a child widget, such as
3346
QLineEdit, to actually handle the focus. In this case, the widget
3347
can set the line edit to be its focus proxy.
3349
setFocusProxy() sets the widget which will actually get focus when
3350
"this widget" gets it. If there is a focus proxy, setFocus() and
3351
hasFocus() operate on the focus proxy.
3356
void QWidget::setFocusProxy(QWidget * w)
3359
if (!w && !d->extra)
3362
for (QWidget* fp = w; fp; fp = fp->focusProxy()) {
3364
qWarning("%s (%s): already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData());
3370
d->extra->focus_proxy = w;
3375
Returns the focus proxy, or 0 if there is no focus proxy.
3380
QWidget * QWidget::focusProxy() const
3383
return d->extra ? (QWidget *)d->extra->focus_proxy : 0;
3388
\property QWidget::focus
3389
\brief whether this widget (or its focus proxy) has the keyboard
3392
Effectively equivalent to \c {QApplication::focusWidget() == this}.
3394
\sa setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget()
3396
bool QWidget::hasFocus() const
3398
const QWidget* w = this;
3399
while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
3400
w = w->d_func()->extra->focus_proxy;
3401
return (QApplication::focusWidget() == w);
3405
Gives the keyboard input focus to this widget (or its focus
3406
proxy) if this widget or one of its parents is the \link
3407
isActiveWindow() active window\endlink. The \a reason argument will
3408
be passed into any focus event sent from this function, it is used
3409
to give an explanation of what caused the widget to get focus.
3411
First, a focus out event is sent to the focus widget (if any) to
3412
tell it that it is about to lose the focus. Then a focus in event
3413
is sent to this widget to tell it that it just received the focus.
3414
(Nothing happens if the focus in and focus out widgets are the
3417
setFocus() gives focus to a widget regardless of its focus policy,
3418
but does not clear any keyboard grab (see grabKeyboard()).
3420
Be aware that if the widget is hidden, it will not accept focus.
3422
\warning If you call setFocus() in a function which may itself be
3423
called from focusOutEvent() or focusInEvent(), you may get an
3426
\sa hasFocus() clearFocus() focusInEvent() focusOutEvent()
3427
setFocusPolicy() QApplication::focusWidget() grabKeyboard()
3428
grabMouse(), {Keyboard Focus}
3431
void QWidget::setFocus(Qt::FocusReason reason)
3437
while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
3438
f = f->d_func()->extra->focus_proxy;
3440
if (QApplication::focusWidget() == f
3441
#if defined(Q_WS_WIN)
3442
&& GetFocus() == f->winId()
3450
while (w && w->isHidden()) {
3451
w->d_func()->focus_child = f;
3452
w = w->isWindow() ? 0 : w->parentWidget();
3456
w->d_func()->focus_child = f;
3457
w = w->isWindow() ? 0 : w->parentWidget();
3461
if (f->isActiveWindow()) {
3462
QWidget *prev = QApplication::focusWidget();
3464
// This part is never executed when Q_WS_X11? Preceding XFocusOut
3465
// had already reset focus_widget when received XFocusIn
3467
// Don't reset input context explicitly here. Whether reset or not
3468
// when focusing out is a responsibility of input methods. So we
3469
// delegate the responsibility to input context via
3470
// unfocusInputContext(). See 'Preedit preservation' section of
3473
#if !defined(Q_WS_MAC)
3474
prev->d_func()->unfocusInputContext();
3476
prev->resetInputContext();
3481
QApplicationPrivate::setFocusWidget(f, reason);
3482
f->d_func()->focusInputContext();
3484
#if defined(Q_WS_WIN)
3485
if (!(f->window()->windowType() == Qt::Popup))
3486
SetFocus(f->winId());
3489
#ifndef QT_NO_ACCESSIBILITY
3490
QAccessible::updateAccessibility(f, 0, QAccessible::Focus);
3492
#if defined(Q_WS_WIN)
3499
\fn void QWidget::setFocus()
3502
Gives the keyboard input focus to this widget (or its focus
3503
proxy) if this widget or one of its parents is the
3504
\l{isActiveWindow()}{active window}.
3508
Takes keyboard input focus from the widget.
3510
If the widget has active focus, a \link focusOutEvent() focus out
3511
event\endlink is sent to this widget to tell it that it is about
3514
This widget must enable focus setting in order to get the keyboard
3515
input focus, i.e. it must call setFocusPolicy().
3517
\sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(),
3518
setFocusPolicy(), QApplication::focusWidget()
3521
void QWidget::clearFocus()
3524
while (w && w->d_func()->focus_child == this) {
3525
w->d_func()->focus_child = 0;
3526
w = w->isWindow() ? 0 : w->parentWidget();
3529
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
3531
d->unfocusInputContext();
3533
QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason);
3534
#if defined(Q_WS_WIN)
3535
if (!(windowType() == Qt::Popup) && GetFocus() == winId())
3539
#ifndef QT_NO_ACCESSIBILITY
3540
QAccessible::updateAccessibility(this, 0, QAccessible::Focus);
3542
#if defined(Q_WS_WIN)
3550
\fn bool QWidget::focusNextChild()
3552
Finds a new widget to give the keyboard focus to, as appropriate
3553
for \key Tab, and returns true if it can find a new widget, or
3556
This is the same as focusNextPrevChild(true).
3558
\sa focusPreviousChild()
3562
\fn bool QWidget::focusPreviousChild()
3564
Finds a new widget to give the keyboard focus to, as appropriate
3565
for \key Shift+Tab, and returns true if it can find a new widget,
3566
or false if it can't.
3568
This is the same as focusNextPrevChild(false).
3570
\sa focusNextChild()
3574
Finds a new widget to give the keyboard focus to, as appropriate
3575
for Tab and Shift+Tab, and returns true if it can find a new
3576
widget, or false if it can't.
3578
If \a next is true, this function searches "forwards", if \a next
3579
is false, it searches "backwards".
3581
Sometimes, you will want to reimplement this function. For
3582
example, a web browser might reimplement it to move its "current
3583
active link" forward or backward, and call
3584
focusNextPrevChild() only when it reaches the last or
3585
first link on the "page".
3587
Child widgets call focusNextPrevChild() on their parent widgets,
3588
but only the window that contains the child widgets decides where
3589
to redirect focus. By reimplementing this function for an object,
3590
you thus gain control of focus traversal for all child widgets.
3592
\sa focusNextChild(), focusPreviousChild()
3595
bool QWidget::focusNextPrevChild(bool next)
3597
QWidget* p = parentWidget();
3598
if (!isWindow() && p)
3599
return p->focusNextPrevChild(next);
3601
extern bool qt_tab_all_widgets;
3602
uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
3604
QWidget *f = focusWidget();
3609
QWidget *test = f->d_func()->focus_next;
3610
while (test && test != f) {
3611
if ((test->focusPolicy() & focus_flag) == focus_flag
3612
&& !(test->d_func()->extra && test->d_func()->extra->focus_proxy)
3613
&& test->isVisibleTo(this) && test->isEnabled()) {
3618
test = test->d_func()->focus_next;
3621
extern bool qt_in_tab_key_event; // defined in qapplication.cpp
3622
if (qt_in_tab_key_event) {
3623
w->window()->setAttribute(Qt::WA_KeyboardFocusChange);
3628
w->setFocus(next ? Qt::TabFocusReason : Qt::BacktabFocusReason);
3633
Returns the last child of this widget that setFocus had been
3634
called on. For top level widgets this is the widget that will get
3635
focus in case this window gets activated
3637
This is not the same as QApplication::focusWidget(), which returns
3638
the focus widget in the currently active window.
3641
QWidget *QWidget::focusWidget() const
3643
return const_cast<QWidget *>(d_func()->focus_child);
3647
Returns the next widget in this widget's focus chain.
3649
QWidget *QWidget::nextInFocusChain() const
3651
return const_cast<QWidget *>(d_func()->focus_next);
3655
\property QWidget::isActiveWindow
3656
\brief whether this widget's window is the active window
3658
The active window is the window that contains the widget that
3661
When popup windows are visible, this property is true for both the
3662
active window \e and for the popup.
3664
\sa activateWindow(), QApplication::activeWindow()
3666
bool QWidget::isActiveWindow() const
3668
QWidget *tlw = window();
3669
if((windowType() == Qt::SubWindow) && parentWidget())
3670
tlw = parentWidget()->window();
3671
if(tlw == qApp->activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
3676
ProcessSerialNumber current, front;
3677
GetCurrentProcess(¤t);
3678
GetFrontProcess(&front);
3679
if(SameProcess(¤t, &front, &compare) == noErr && !compare)
3682
extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
3683
if(qt_mac_is_macdrawer(tlw) &&
3684
tlw->parentWidget() && tlw->parentWidget()->isActiveWindow())
3687
if(style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, this)) {
3688
if(((tlw->windowType() == Qt::Dialog) || (tlw->windowType() == Qt::Tool)) &&
3689
!tlw->testAttribute(Qt::WA_ShowModal) &&
3690
(!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
3692
QWidget *w = qApp->activeWindow();
3693
if(!(windowType() == Qt::SubWindow) && w && (w->windowType() == Qt::SubWindow) &&
3694
w->parentWidget()->window() == tlw)
3696
while(w && ((tlw->windowType() == Qt::Dialog) || (tlw->windowType() == Qt::Tool)) &&
3697
!w->testAttribute(Qt::WA_ShowModal) && w->parentWidget()) {
3698
w = w->parentWidget()->window();
3703
#if defined(Q_WS_WIN32)
3704
HWND parent = tlw->winId();
3705
HWND topparent = GetActiveWindow();
3707
parent = ::GetParent(parent);
3708
if (parent && parent == topparent)
3717
Moves the \a second widget around the ring of focus widgets so
3718
that keyboard focus moves from the \a first widget to the \a
3719
second widget when the Tab key is pressed.
3721
Note that since the tab order of the \a second widget is changed,
3722
you should order a chain like this:
3725
setTabOrder(a, b); // a to b
3726
setTabOrder(b, c); // a to b to c
3727
setTabOrder(c, d); // a to b to c to d
3733
setTabOrder(c, d); // c to d WRONG
3734
setTabOrder(a, b); // a to b AND c to d
3735
setTabOrder(b, c); // a to b to c, but not c to d
3738
If \a first or \a second has a focus proxy, setTabOrder()
3739
correctly substitutes the proxy.
3741
\sa setFocusPolicy(), setFocusProxy(), {Keyboard Focus}
3743
void QWidget::setTabOrder(QWidget* first, QWidget *second)
3745
if (!first || !second || first->focusPolicy() == Qt::NoFocus || second->focusPolicy() == Qt::NoFocus)
3748
QWidget *fp = first->focusProxy();
3750
// If first is redirected, set first to the last child of first
3751
// that can take keyboard focus so that second is inserted after
3752
// that last child, and the focus order within first is (more
3753
// likely to be) preserved.
3754
QList<QWidget *> l = qFindChildren<QWidget *>(first);
3755
for (int i = l.size()-1; i >= 0; --i) {
3756
QWidget * next = l.at(i);
3757
if (next->window() == fp->window()) {
3759
if (fp->focusPolicy() != Qt::NoFocus)
3766
if (QWidget *sp = second->focusProxy())
3769
QWidget *p = second;
3770
while (p->d_func()->focus_next != second)
3771
p = p->d_func()->focus_next;
3772
p->d_func()->focus_next = second->d_func()->focus_next;
3774
second->d_func()->focus_next = first->d_func()->focus_next;
3775
first->d_func()->focus_next = second;
3780
Moves the relevant subwidgets of this widget from the \a oldtlw's
3781
tab chain to that of the new parent, if there's anything to move and
3784
This function is called from QWidget::reparent() *after* the widget
3785
has been reparented.
3790
void QWidgetPrivate::reparentFocusWidgets(QWidget * oldtlw)
3793
if (oldtlw == q->window())
3794
return; // nothing to do
3797
focus_child->clearFocus();
3799
// seperate the focus chain
3800
QWidget *topLevel = q->window();
3802
QWidget *firstOld = 0;
3803
QWidget *firstNew = 0;
3807
if (w == q || q->isAncestorOf(w)) {
3811
n->d_func()->focus_next = w;
3817
o->d_func()->focus_next = w;
3820
} while ((w = w->d_func()->focus_next) != q);
3822
o->d_func()->focus_next = firstOld;
3824
n->d_func()->focus_next = firstNew;
3826
if (!q->isWindow()) {
3829
while (w->d_func()->focus_next != topLevel)
3830
w = w->d_func()->focus_next;
3831
w->d_func()->focus_next = q;
3832
n->d_func()->focus_next = topLevel;
3834
n->d_func()->focus_next = q;
3840
Measures the shortest distance from a point to a rect.
3842
This function is called from QDesktopwidget::screen(QPoint) to find the
3843
closest screen for a point.
3845
int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r)
3849
if (p.x() < r.left())
3850
dx = r.left() - p.x();
3851
else if (p.x() > r.right())
3852
dx = p.x() - r.right();
3853
if (p.y() < r.top())
3854
dy = r.top() - p.y();
3855
else if (p.y() > r.bottom())
3856
dy = p.y() - r.bottom();
3861
\property QWidget::frameSize
3862
\brief the size of the widget including any window frame
3864
QSize QWidget::frameSize() const
3867
if (isWindow() && !(windowType() == Qt::Popup)) {
3868
if (data->fstrut_dirty)
3869
d->updateFrameStrut();
3870
QWidget *that = (QWidget *) this;
3871
QTLWExtra *top = that->d_func()->topData();
3872
return QSize(data->crect.width() + top->fleft + top->fright,
3873
data->crect.height() + top->ftop + top->fbottom);
3875
return data->crect.size();
3878
/*! \fn void QWidget::move(int x, int y)
3882
This corresponds to move(QPoint(\a x, \a y)).
3885
void QWidget::move(const QPoint &p)
3888
QPoint oldp = pos();
3889
setAttribute(Qt::WA_Moved);
3890
d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(),
3891
p.y() + geometry().y() - QWidget::y(),
3892
width(), height(), true);
3894
d->updateInheritedBackground();
3897
/*! \fn void QWidget::resize(int w, int h)
3900
This corresponds to resize(QSize(\a w, \a h)).
3903
void QWidget::resize(const QSize &s)
3906
setAttribute(Qt::WA_Resized);
3907
QSize olds = size();
3908
d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false);
3909
if (testAttribute(Qt::WA_ContentsPropagated) && olds != size())
3910
d->updatePropagatedBackground();
3913
void QWidget::setGeometry(const QRect &r)
3916
QPoint oldp = pos();
3917
QSize olds = size();
3918
setAttribute(Qt::WA_Resized);
3919
setAttribute(Qt::WA_Moved);
3920
d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true);
3922
if (testAttribute(Qt::WA_ContentsPropagated) && olds != size())
3923
d->updatePropagatedBackground();
3924
else if (oldp != pos())
3925
d->updateInheritedBackground();
3929
/*!\fn void QWidget::setGeometry(int x, int y, int w, int h)
3932
This corresponds to setGeometry(QRect(\a x, \a y, \a w, \a h)).
3936
Sets the margins around the contents of the widget to have the
3937
sizes \a left, \a top, \a right, and \a bottom. The margins are
3938
used by the layout system, and may be used by subclasses to
3939
specify the area to draw in (e.g. excluding the frame).
3941
Changing the margins will trigger a resizeEvent().
3943
\sa contentsRect(), getContentsMargins()
3945
void QWidget::setContentsMargins(int left, int top, int right, int bottom)
3948
if (left == d->leftmargin && top == d->topmargin
3949
&& right == d->rightmargin && bottom == d->bottommargin)
3951
d->leftmargin = left;
3953
d->rightmargin = right;
3954
d->bottommargin = bottom;
3956
if (QLayout *l=d->layout)
3957
l->update(); //force activate; will do updateGeometry
3963
QResizeEvent e(data->crect.size(), data->crect.size());
3964
QApplication::sendEvent(this, &e);
3966
setAttribute(Qt::WA_PendingResizeEvent, true);
3970
/*! Returns the widget's contents margins for \a left, \a top, \a
3971
right, and \a bottom.
3973
\sa setContentsMargins(), contentsRect()
3975
void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) const
3979
*left = d->leftmargin;
3981
*top = d->topmargin;
3983
*right = d->rightmargin;
3985
*bottom = d->bottommargin;
3989
Returns the area inside the widget's margins.
3991
\sa setContentsMargins(), getContentsMargins()
3993
QRect QWidget::contentsRect() const
3996
return QRect(QPoint(d->leftmargin, d->topmargin),
3997
QPoint(data->crect.width() - 1 - d->rightmargin,
3998
data->crect.height() - 1 - d->bottommargin));
4004
\fn void QWidget::customContextMenuRequested(const QPoint &pos)
4006
This signal is emitted when the widget's \l contextMenuPolicy is
4007
Qt::CustomContextMenu, and the user has requested a context menu on
4008
the widget. The position \a pos is the position of the request in
4011
\sa mapToGlobal() QMenu contextMenuPolicy
4015
\property QWidget::contextMenuPolicy
4016
\brief how the widget shows a context menu
4018
The default value of this property is Qt::DefaultContextMenu,
4019
which means the contextMenuEvent() handler is called. Other values
4020
are Qt::NoContextMenu, Qt::ActionsContextMenu, and
4021
Qt::CustomContextMenu. With Qt::CustomContextMenu, the signal
4022
customContextMenuRequested() is emitted.
4024
\sa contextMenuEvent() customContextMenuRequested()
4027
Qt::ContextMenuPolicy QWidget::contextMenuPolicy() const
4029
return (Qt::ContextMenuPolicy)data->context_menu_policy;
4032
void QWidget::setContextMenuPolicy(Qt::ContextMenuPolicy policy)
4034
data->context_menu_policy = (uint) policy;
4038
\property QWidget::focusPolicy
4039
\brief the way the widget accepts keyboard focus
4041
The policy is \c Qt::TabFocus if the widget accepts keyboard
4042
focus by tabbing, \c Qt::ClickFocus if the widget accepts
4043
focus by clicking, \c Qt::StrongFocus if it accepts both, and
4044
\c Qt::NoFocus (the default) if it does not accept focus at
4047
You must enable keyboard focus for a widget if it processes
4048
keyboard events. This is normally done from the widget's
4049
constructor. For instance, the QLineEdit constructor calls
4050
setFocusPolicy(Qt::StrongFocus).
4052
\sa focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), enabled
4056
Qt::FocusPolicy QWidget::focusPolicy() const
4058
return (Qt::FocusPolicy)data->focus_policy;
4061
void QWidget::setFocusPolicy(Qt::FocusPolicy policy)
4063
data->focus_policy = (uint) policy;
4067
\property QWidget::updatesEnabled
4068
\brief whether updates are enabled
4070
An updates enabled widget receives paint events and has a system
4071
background; a disabled widget does not. This also implies that
4072
calling update() and repaint() has no effect if updates are
4075
setUpdatesEnabled() is normally used to disable updates for a
4076
short period of time, for instance to avoid screen flicker during
4077
large changes. In Qt, widgets normally do not generate screen
4078
flicker, but on X11 the server might erase regions on the screen
4079
when widgets get hidden before they can be replaced by other
4080
widgets. Disabling updates solves this.
4084
setUpdatesEnabled(false);
4086
setUpdatesEnabled(true);
4089
Disabling a widget implicitly disables all its children. Enabling
4090
respectively enables all child widgets unless they have been
4091
explicitly disabled. Re-enabling updates implicitly calls update()
4096
void QWidget::setUpdatesEnabled(bool enable)
4099
setAttribute(Qt::WA_ForceUpdatesDisabled, !enable);
4100
d->setUpdatesEnabled_helper(enable);
4103
/*! \fn void QWidget::show()
4105
Shows the widget and its child widgets. This function is
4106
equivalent to setVisible(true).
4108
\sa showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
4109
showNormal(), isVisible()
4115
Makes the widget visible in the isVisible() meaning of the word.
4116
It is only called for toplevels or widgets with visible parents.
4118
void QWidgetPrivate::show_recursive()
4121
// polish if necessary
4122
q->ensurePolished();
4126
QApplication::sendPostedEvents(q, QEvent::ChildInserted);
4128
#ifndef QT_NO_LAYOUT
4129
if (!q->isWindow() && q->parentWidget()->d_func()->layout)
4130
q->parentWidget()->d_func()->layout->activate();
4132
#ifndef QT_NO_LAYOUT
4133
// activate our layout before we and our children become visible
4141
void QWidgetPrivate::show_helper()
4144
data.in_show = true; // qws optimization
4145
// make sure we receive pending move and resize events
4146
if (q->testAttribute(Qt::WA_PendingMoveEvent)) {
4147
QMoveEvent e(data.crect.topLeft(), data.crect.topLeft());
4148
QApplication::sendEvent(q, &e);
4149
q->setAttribute(Qt::WA_PendingMoveEvent, false);
4151
if (q->testAttribute(Qt::WA_PendingResizeEvent)) {
4152
QResizeEvent e(data.crect.size(), data.crect.size());
4153
QApplication::sendEvent(q, &e);
4154
q->setAttribute(Qt::WA_PendingResizeEvent, false);
4157
// become visible before showing all children
4158
q->setAttribute(Qt::WA_WState_Visible);
4160
// finally show all children recursively
4161
showChildren(false);
4164
if (q->parentWidget() && sendChildEvents)
4165
QApplication::sendPostedEvents(q->parentWidget(),
4166
QEvent::ChildInserted);
4170
// popup handling: new popups and tools need to be raised, and
4171
// exisiting popups must be closed. Also propagate the current
4172
// windows's KeyboardFocusChange status.
4173
if (q->isWindow()) {
4174
if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) {
4176
if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange))
4177
q->setAttribute(Qt::WA_KeyboardFocusChange);
4179
while (QApplication::activePopupWidget()) {
4180
if (!QApplication::activePopupWidget()->close())
4186
// On Windows, show the popup now so that our own focus handling
4187
// stores the correct old focus widget even if it's stolen in the
4189
#if defined(Q_WS_WIN)
4190
if ((q->windowType() == Qt::Popup))
4191
qApp->d_func()->openPopup(q);
4194
// send the show event before showing the window
4195
QShowEvent showEvent;
4196
QApplication::sendEvent(q, &showEvent);
4198
if (q->testAttribute(Qt::WA_ShowModal))
4199
// QApplicationPrivate::enterModal *before* show, otherwise the initial
4200
// stacking might be wrong
4201
QApplicationPrivate::enterModal(q);
4203
q->setAttribute(Qt::WA_Mapped);
4206
#if !defined(Q_WS_WIN)
4207
if ((q->windowType() == Qt::Popup))
4208
qApp->d_func()->openPopup(q);
4211
#ifndef QT_NO_ACCESSIBILITY
4212
QAccessible::updateAccessibility(q, 0, QAccessible::ObjectShow);
4215
data.in_show = false; // reset qws optimization
4218
/*! \fn void QWidget::hide()
4220
Hides the widget. This function is equivalent to
4223
\sa hideEvent(), isHidden(), show(), setVisible(), isVisible(), close()
4228
void QWidgetPrivate::hide_helper()
4231
if ((q->windowType() == Qt::Popup))
4232
qApp->d_func()->closePopup(q);
4234
// Move test modal here. Otherwise, a modal dialog could get
4235
// destroyed and we lose all access to its parent because we haven't
4236
// left modality. (Eg. modal Progress Dialog)
4237
if (q->testAttribute(Qt::WA_ShowModal))
4238
QApplicationPrivate::leaveModal(q);
4240
#if defined(Q_WS_WIN)
4241
if (q->isWindow() && !(q->windowType() == Qt::Popup) && q->parentWidget() && q->isActiveWindow())
4242
q->parentWidget()->activateWindow(); // Activate parent
4245
q->setAttribute(Qt::WA_Mapped, false);
4248
bool wasVisible = q->testAttribute(Qt::WA_WState_Visible);
4251
q->setAttribute(Qt::WA_WState_Visible, false);
4255
QHideEvent hideEvent;
4256
QApplication::sendEvent(q, &hideEvent);
4257
hideChildren(false);
4259
// next bit tries to move the focus if the focus widget is now
4262
QWidget *fw = QApplication::focusWidget();
4263
while (fw && !fw->isWindow()) {
4265
q->focusNextPrevChild(true);
4268
fw = fw->parentWidget();
4273
#ifndef QT_NO_ACCESSIBILITY
4275
QAccessible::updateAccessibility(q, 0, QAccessible::ObjectHide);
4277
#ifndef QT_NO_LAYOUT
4278
// invalidate layout similar to updateGeometry()
4279
if (!q->isWindow() && q->parentWidget()) {
4280
if (q->parentWidget()->d_func()->layout)
4281
q->parentWidget()->d_func()->layout->update();
4283
QApplication::postEvent(q->parentWidget(), new QEvent(QEvent::LayoutRequest));
4289
\fn bool QWidget::isHidden() const
4291
Returns true if the widget is hidden, otherwise returns false.
4293
A hidden widget will only become visible when show() is called on
4294
it. It will not be automatically shown when the parent is shown.
4296
To check visiblity, use !isVisible() instead (notice the exclamation mark).
4298
isHidden() implies !isVisible(), but a widget can be not visible
4299
and not hidden at the same time. This is the case for widgets that are children of
4300
widgets that are not visible.
4303
Widgets are hidden if they were created as independent
4304
windows or as children of visible widgets, or if hide() or setVisible(false) was called.
4309
void QWidget::setVisible(bool visible)
4311
if (visible) { // show
4312
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
4316
if (windowType() == Qt::Window)
4317
QApplicationPrivate::applyX11SpecificCommandLineArguments(this);
4320
bool wasResized = testAttribute(Qt::WA_Resized);
4321
Qt::WindowStates initialWindowState = windowState();
4324
if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon))
4325
d->setWindowIcon_sys();
4327
// polish if necessary
4330
// remember that show was called explicitly
4331
setAttribute(Qt::WA_WState_ExplicitShowHide);
4332
// whether we need to inform the parent widget immediately
4333
bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden);
4334
// we are no longer hidden
4335
setAttribute(Qt::WA_WState_Hidden, false);
4337
if (needUpdateGeometry)
4341
QApplication::sendPostedEvents(this, QEvent::ChildInserted);
4343
#ifndef QT_NO_LAYOUT
4344
if (!isWindow() && parentWidget()->d_func()->layout)
4345
parentWidget()->d_func()->layout->activate();
4347
#ifndef QT_NO_LAYOUT
4348
// activate our layout before we and our children become visible
4350
d->layout->activate();
4353
// adjust size if necessary
4355
&& (isWindow() || !parentWidget()->d_func()->layout)) {
4358
if (windowState() != initialWindowState)
4359
setWindowState(initialWindowState);
4363
setAttribute(Qt::WA_Resized, false);
4366
setAttribute(Qt::WA_KeyboardFocusChange, false);
4368
if (isWindow() || parentWidget()->isVisible())
4371
QEvent showToParentEvent(QEvent::ShowToParent);
4372
QApplication::sendEvent(this, &showToParentEvent);
4374
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))
4378
setAttribute(Qt::WA_WState_Hidden);
4379
if (testAttribute(Qt::WA_WState_ExplicitShowHide))
4382
setAttribute(Qt::WA_WState_ExplicitShowHide);
4383
QEvent hideToParentEvent(QEvent::HideToParent);
4384
QApplication::sendEvent(this, &hideToParentEvent);
4388
/*!\fn void QWidget::setHidden(bool hidden)
4390
Convenience function, equivalent to setVisible(!\a hidden).
4393
/*!\fn void QWidget::setShown(bool shown)
4395
Use setVisible(\a shown) instead.
4398
void QWidgetPrivate::showChildren(bool spontaneous)
4400
QList<QObject*> childList = children;
4401
for (int i = 0; i < childList.size(); ++i) {
4402
QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
4404
|| widget->isWindow()
4405
|| widget->testAttribute(Qt::WA_WState_Hidden))
4408
widget->setAttribute(Qt::WA_Mapped);
4409
widget->d_func()->showChildren(true);
4411
QApplication::sendSpontaneousEvent(widget, &e);
4413
if (widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
4414
widget->d_func()->show_recursive();
4421
void QWidgetPrivate::hideChildren(bool spontaneous)
4423
QList<QObject*> childList = children;
4424
for (int i = 0; i < childList.size(); ++i) {
4425
QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
4426
if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden))
4429
widget->setAttribute(Qt::WA_Mapped, false);
4431
widget->setAttribute(Qt::WA_WState_Visible, false);
4432
widget->d_func()->hideChildren(spontaneous);
4435
QApplication::sendSpontaneousEvent(widget, &e);
4437
QApplication::sendEvent(widget, &e);
4441
bool QWidgetPrivate::close_helper(CloseMode mode)
4443
if (data.is_closing)
4447
data.is_closing = 1;
4449
QPointer<QWidget> that = q;
4452
bool isMain = (QApplicationPrivate::main_widget == q);
4454
bool quitOnClose = q->testAttribute(Qt::WA_QuitOnClose);
4456
if (mode != CloseNoEvent) {
4458
if (mode == CloseWithSpontaneousEvent)
4459
QApplication::sendSpontaneousEvent(q, &e);
4461
QApplication::sendEvent(q, &e);
4462
if (!that.isNull() && !e.isAccepted()) {
4463
data.is_closing = 0;
4468
if (!that.isNull() && !q->isHidden())
4476
/* if there is no non-withdrawn top level window left
4477
(except the desktop, popups, or dialogs/tools with
4478
parents), we emit the lastWindowClosed signal */
4479
QWidgetList list = QApplication::topLevelWidgets();
4480
bool lastWindowClosed = true;
4481
for (int i = 0; i < list.size(); ++i) {
4482
QWidget *w = list.at(i);
4483
if (!w->isVisible() || !w->testAttribute(Qt::WA_QuitOnClose))
4485
lastWindowClosed = false;
4488
if (lastWindowClosed)
4489
QApplicationPrivate::emitLastWindowClosed();
4492
if (!that.isNull()) {
4493
data.is_closing = 0;
4494
if (q->testAttribute(Qt::WA_DeleteOnClose)) {
4495
q->setAttribute(Qt::WA_DeleteOnClose, false);
4504
Closes this widget. Returns true if the widget was closed;
4505
otherwise returns false.
4507
First it sends the widget a QCloseEvent. The widget is \link
4508
hide() hidden\endlink if it \link QCloseEvent::accept()
4509
accepts\endlink the close event. If it \link QCloseEvent::ignore()
4510
ignores\endlink the event, nothing happens. The default
4511
implementation of QWidget::closeEvent() accepts the close event.
4513
If the widget has the \c Qt::WA_DeleteOnClose flag, the widget
4514
is also deleted. A close events is delivered to the widget no
4515
matter if the widget is visible or not.
4517
The \l QApplication::lastWindowClosed() signal is emitted when the
4518
last visible top level widget with the Qt::WA_QuitOnClose
4519
attribute set is closed. By default this attribute is set for all
4520
widgets except transient top level widgets such as splash screens,
4521
popup menus, and dialogs.
4525
bool QWidget::close()
4527
return d_func()->close_helper(QWidgetPrivate::CloseWithEvent);
4531
\property QWidget::visible
4532
\brief whether the widget is visible
4534
Calling setVisible(true) or show() sets the widget to visible
4535
status if all its parent widgets up to the window are visible. If
4536
an ancestor is not visible, the widget won't become visible until
4537
all its ancestors are shown. If its size or position has changed,
4538
Qt guarantees that a widget gets move and resize events just
4539
before it is shown. If the widget has not been resized yet, Qt
4540
will adjust the widget's size to a useful default using
4543
Calling setVisible(false) or hide() hides a widget explicitly. An
4544
explicitly hidden widget will never become visible, even if all
4545
its ancestors become visible, unless you show it.
4547
A widget receives show and hide events when its visibility status
4548
changes. Between a hide and a show event, there is no need to
4549
waste CPU cycles preparing or displaying information to the user.
4550
A video application, for example, might simply stop generating new
4553
A widget that happens to be obscured by other windows on the
4554
screen is considered to be visible. The same applies to iconified
4555
windows and windows that exist on another virtual
4556
desktop (on platforms that support this concept). A widget
4557
receives spontaneous show and hide events when its mapping status
4558
is changed by the window system, e.g. a spontaneous hide event
4559
when the user minimizes the window, and a spontaneous show event
4560
when the window is restored again.
4562
You almost never have to reimplement the setVisible() function. If
4563
you need to change some settings before a widget is shown, use
4564
showEvent() instead. If you need to do some delayed initialization
4565
use the Polish event delivered to the event() method
4567
\sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(),
4568
showEvent(), hideEvent()
4573
Returns true if this widget would become visible if \a ancestor is
4574
shown; otherwise returns false.
4576
The true case occurs if neither the widget itself nor any parent
4577
up to but excluding \a ancestor has been explicitly hidden.
4579
This function will still return true if the widget is obscured by
4580
other windows on the screen, but could be physically visible if it
4581
or they were to be moved.
4583
isVisibleTo(0) is identical to isVisible().
4585
\sa show() hide() isVisible()
4588
bool QWidget::isVisibleTo(QWidget* ancestor) const
4592
const QWidget * w = this;
4596
&& w->parentWidget()
4597
&& w->parentWidget() != ancestor)
4598
w = w->parentWidget();
4599
return !w->isHidden();
4603
QRect QWidget::visibleRect() const
4605
return d_func()->clipRect();
4610
Returns the unobscured region where paint events can occur.
4612
For visible widgets, this is an approximation of the area not
4613
covered by other widgets; otherwise, this is an empty region.
4615
The repaint() function calls this function if necessary, so in
4616
general you do not need to call it.
4619
QRegion QWidget::visibleRegion() const
4621
return d_func()->clipRect();
4626
Adjusts the size of the widget to fit the contents.
4628
Uses sizeHint() if valid (i.e if the size hint's width and height
4629
are \>= 0), otherwise sets the size to the children rectangle (the
4630
union of all child widget geometries). For toplevel widgets, the
4631
function also takes the screen size into account.
4633
\sa sizeHint(), childrenRect()
4636
void QWidget::adjustSize()
4640
QSize s = sizeHint();
4643
Qt::Orientations exp;
4644
#ifndef QT_NO_LAYOUT
4645
if (QLayout *l = layout()) {
4646
if (l->hasHeightForWidth())
4647
s.setHeight(l->totalHeightForWidth(s.width()));
4648
exp = l->expandingDirections();
4652
if (sizePolicy().hasHeightForWidth())
4653
s.setHeight(heightForWidth(s.width()));
4654
exp = sizePolicy().expandingDirections();
4656
if (exp & Qt::Horizontal)
4657
s.setWidth(qMax(s.width(), 200));
4658
if (exp & Qt::Vertical)
4659
s.setHeight(qMax(s.height(), 150));
4660
#if defined(Q_WS_X11)
4661
QRect screen = QApplication::desktop()->screenGeometry(x11Info().screen());
4663
QRect screen = QApplication::desktop()->screenGeometry(pos());
4665
s.setWidth(qMin(s.width(), screen.width()*2/3));
4666
s.setHeight(qMin(s.height(), screen.height()*2/3));
4670
QRect r = childrenRect(); // get children rectangle
4673
s = r.size() + QSize(2 * r.x(), 2 * r.y());
4681
\property QWidget::sizeHint
4682
\brief the recommended size for the widget
4684
If the value of this property is an invalid size, no size is
4687
The default implementation of sizeHint() returns an invalid size
4688
if there is no layout for this widget, and returns the layout's
4689
preferred size otherwise.
4691
\sa QSize::isValid(), minimumSizeHint(), sizePolicy(),
4692
setMinimumSize(), updateGeometry()
4695
QSize QWidget::sizeHint() const
4698
#ifndef QT_NO_LAYOUT
4700
return d->layout->totalSizeHint();
4702
return QSize(-1, -1);
4706
\property QWidget::minimumSizeHint
4707
\brief the recommended minimum size for the widget
4709
If the value of this property is an invalid size, no minimum size
4712
The default implementation of minimumSizeHint() returns an invalid
4713
size if there is no layout for this widget, and returns the
4714
layout's minimum size otherwise. Most built-in widgets reimplement
4717
\l QLayout will never resize a widget to a size smaller than the
4718
minimum size hint unless minimumSize() is set or the size policy is
4719
set to \c QSizePolicy::Ignore. If minimumSize() is set, the minimum
4720
size hint will be ignored.
4722
\sa QSize::isValid(), resize(), setMinimumSize(), sizePolicy()
4724
QSize QWidget::minimumSizeHint() const
4727
#ifndef QT_NO_LAYOUT
4729
return d->layout->totalMinimumSize();
4731
return QSize(-1, -1);
4736
\fn QWidget *QWidget::parentWidget() const
4738
Returns the parent of this widget, or 0 if it does not have any
4744
Returns true if this widget is a parent, (or grandparent and so on
4745
to any level), of the given \a child, and both widgets are within
4746
the same window; otherwise returns false.
4749
bool QWidget::isAncestorOf(const QWidget *child) const
4754
if (child->isWindow())
4756
child = child->parentWidget();
4763
/*****************************************************************************
4764
QWidget event handling
4765
*****************************************************************************/
4768
This is the main event handler; it handles event \a e. You can
4769
reimplement this function in a subclass, but we recommend using
4770
one of the specialized event handlers instead.
4772
Key press and release events are treated differently from other
4773
events. event() checks for Tab and Shift+Tab and tries to move the
4774
focus appropriately. If there is no widget to move the focus to
4775
(or the key press is not Tab or Shift+Tab), event() calls
4778
Mouse and tablet event handling is also slightly special: only
4779
when the widget is \l enabled, event() will call the specialized
4780
handlers such as mousePressEvent(); otherwise it will discard the
4783
This function returns true if the event was recognized, otherwise
4784
it returns false. If the recognized event was accepted (see \l
4785
QEvent::accepted), any further processing such as event
4786
propagation to the parent widget stops.
4788
\sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(),
4789
keyPressEvent(), keyReleaseEvent(), leaveEvent(),
4790
mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(),
4791
mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(),
4792
QObject::event(), QObject::timerEvent()
4795
bool QWidget::event(QEvent *e)
4799
// ignore mouse events when disabled
4802
case QEvent::TabletPress:
4803
case QEvent::TabletRelease:
4804
case QEvent::TabletMove:
4805
case QEvent::MouseButtonPress:
4806
case QEvent::MouseButtonRelease:
4807
case QEvent::MouseButtonDblClick:
4808
case QEvent::MouseMove:
4809
case QEvent::ContextMenu:
4810
#ifndef QT_NO_WHEELEVENT
4818
switch (e->type()) {
4819
case QEvent::MouseMove:
4820
mouseMoveEvent((QMouseEvent*)e);
4823
case QEvent::MouseButtonPress:
4824
// Don't reset input context here. Whether reset or not is
4825
// a responsibility of input method. reset() will be
4826
// called by mouseHandler() of input method if necessary
4827
// via mousePressEvent() of text widgets.
4829
resetInputContext();
4831
mousePressEvent((QMouseEvent*)e);
4834
case QEvent::MouseButtonRelease:
4835
mouseReleaseEvent((QMouseEvent*)e);
4838
case QEvent::MouseButtonDblClick:
4839
mouseDoubleClickEvent((QMouseEvent*)e);
4841
#ifndef QT_NO_WHEELEVENT
4843
wheelEvent((QWheelEvent*)e);
4846
case QEvent::TabletMove:
4847
case QEvent::TabletPress:
4848
case QEvent::TabletRelease:
4849
tabletEvent((QTabletEvent*)e);
4856
case QEvent::KeyPress: {
4857
QKeyEvent *k = (QKeyEvent *)e;
4859
if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
4860
if (k->key() == Qt::Key_Backtab
4861
|| (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
4862
res = focusNextPrevChild(false);
4863
else if (k->key() == Qt::Key_Tab)
4864
res = focusNextPrevChild(true);
4869
if (!k->isAccepted()
4870
&& k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1
4871
&& d->whatsThis.size()) {
4872
QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImMicroFocus).toRect().center()), d->whatsThis, this);
4878
case QEvent::KeyRelease:
4879
keyReleaseEvent((QKeyEvent*)e);
4881
case QEvent::ShortcutOverride:
4884
case QEvent::InputMethod:
4885
inputMethodEvent((QInputMethodEvent *) e);
4888
case QEvent::PolishRequest:
4892
case QEvent::Polish: {
4893
style()->polish(this);
4894
setAttribute(Qt::WA_WState_Polished);
4895
if (!testAttribute(Qt::WA_SetFont) && !QApplication::font(this).isCopyOf(QApplication::font()))
4897
if (!QApplication::palette(this).isCopyOf(QApplication::palette()))
4898
d->resolvePalette();
4900
if(d->sendChildEvents)
4901
QApplication::sendPostedEvents(this, QEvent::ChildInserted);
4906
case QEvent::ApplicationWindowIconChange:
4907
if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon))
4908
d->setWindowIcon_sys();
4911
case QEvent::FocusIn:
4912
focusInEvent((QFocusEvent*)e);
4915
case QEvent::FocusOut:
4916
focusOutEvent((QFocusEvent*)e);
4920
if (d->statusTip.size()) {
4921
QStatusTipEvent tip(d->statusTip);
4922
QApplication::sendEvent(const_cast<QWidget *>(this), &tip);
4928
if (d->statusTip.size()) {
4930
QStatusTipEvent tip(empty);
4931
QApplication::sendEvent(const_cast<QWidget *>(this), &tip);
4936
case QEvent::HoverEnter:
4937
case QEvent::HoverLeave:
4942
// At this point the event has to be delivered, regardless
4943
// whether the widget isVisible() or not because it
4944
// already went through the filters
4945
paintEvent((QPaintEvent*)e);
4949
moveEvent((QMoveEvent*)e);
4952
case QEvent::Resize:
4953
resizeEvent((QResizeEvent*)e);
4957
closeEvent((QCloseEvent *)e);
4960
case QEvent::ContextMenu:
4961
switch (data->context_menu_policy) {
4962
case Qt::DefaultContextMenu:
4963
contextMenuEvent(static_cast<QContextMenuEvent *>(e));
4965
case Qt::CustomContextMenu:
4966
emit customContextMenuRequested(static_cast<QContextMenuEvent *>(e)->pos());
4968
case Qt::ActionsContextMenu:
4969
if (d->actions.count()) {
4970
QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(e)->globalPos());
4980
#ifndef QT_NO_DRAGANDDROP
4982
dropEvent((QDropEvent*) e);
4985
case QEvent::DragEnter:
4986
dragEnterEvent((QDragEnterEvent*) e);
4989
case QEvent::DragMove:
4990
dragMoveEvent((QDragMoveEvent*) e);
4993
case QEvent::DragLeave:
4994
dragLeaveEvent((QDragLeaveEvent*) e);
4999
showEvent((QShowEvent*) e);
5003
hideEvent((QHideEvent*) e);
5006
case QEvent::ShowWindowRequest:
5011
case QEvent::ApplicationFontChange:
5014
case QEvent::ApplicationPaletteChange:
5015
if (!(windowType() == Qt::Desktop))
5016
d->resolvePalette();
5018
case QEvent::ToolBarChange:
5019
case QEvent::ActivationChange:
5020
case QEvent::EnabledChange:
5021
case QEvent::FontChange:
5022
case QEvent::StyleChange:
5023
case QEvent::PaletteChange:
5024
case QEvent::WindowTitleChange:
5025
case QEvent::IconTextChange:
5026
case QEvent::ModifiedChange:
5027
case QEvent::MouseTrackingChange:
5028
case QEvent::ParentChange:
5029
case QEvent::WindowStateChange:
5033
case QEvent::WindowActivate:
5034
case QEvent::WindowDeactivate: {
5036
windowActivationChange(e->type() != QEvent::WindowActivate);
5039
for(int role=0; role < (int)QPalette::NColorRoles; role++) {
5040
if(data->pal.brush(QPalette::Active, (QPalette::ColorRole)role) !=
5041
data->pal.brush(QPalette::Inactive, (QPalette::ColorRole)role)) {
5042
QPalette::ColorRole bg_role = backgroundRole();
5043
if (!testAttribute(Qt::WA_NoSystemBackground) && bg_role < QPalette::NColorRoles &&
5044
(role == bg_role || (role < bg_role && data->pal.brush(QPalette::Active, bg_role) !=
5045
data->pal.brush(QPalette::Inactive, bg_role))))
5046
d->updateSystemBackground();
5047
else if(role <= QPalette::Shadow)
5053
QList<QObject*> childList = d->children;
5054
for (int i = 0; i < childList.size(); ++i) {
5055
QWidget *w = qobject_cast<QWidget *>(childList.at(i));
5056
if (w && w->isVisible() && !w->isWindow())
5057
QApplication::sendEvent(w, e);
5061
case QEvent::LanguageChange:
5067
case QEvent::LocaleChange:
5069
QList<QObject*> childList = d->children;
5070
for (int i = 0; i < childList.size(); ++i) {
5071
QObject *o = childList.at(i);
5072
QApplication::sendEvent(o, e);
5078
case QEvent::ApplicationLayoutDirectionChange:
5079
d->resolveLayoutDirection();
5082
case QEvent::LayoutDirectionChange:
5084
d->layout->invalidate();
5088
#if defined(Q_WS_X11)
5089
case QEvent::UpdateRequest:
5090
if (!d->invalidated_region.isEmpty()) {
5091
QRegion rgn = d->invalidated_region;
5092
d->invalidated_region = QRegion();
5097
#if defined(Q_WS_QWS)
5098
case QEvent::QWSUpdate:
5099
repaint(static_cast<QWSUpdateEvent*>(e)->region());
5103
case QEvent::WindowBlocked:
5104
case QEvent::WindowUnblocked:
5106
QList<QObject*> childList = d->children;
5107
for (int i = 0; i < childList.size(); ++i) {
5108
QObject *o = childList.at(i);
5109
if (o != qApp->activeModalWidget())
5110
QApplication::sendEvent(o, e);
5115
case QEvent::ToolTip:
5116
if (d->toolTip.size() && isActiveWindow())
5117
QToolTip::showText(static_cast<QHelpEvent*>(e)->globalPos(), d->toolTip, this);
5122
#ifndef QT_NO_WHATSTHIS
5123
case QEvent::WhatsThis:
5124
if (d->whatsThis.size())
5125
QWhatsThis::showText(static_cast<QHelpEvent *>(e)->globalPos(), d->whatsThis, this);
5129
case QEvent::QueryWhatsThis:
5130
if (d->whatsThis.isEmpty())
5134
#ifndef QT_NO_ACCESSIBILITY
5135
case QEvent::AccessibilityDescription:
5136
case QEvent::AccessibilityHelp: {
5137
QAccessibleEvent *ev = static_cast<QAccessibleEvent *>(e);
5140
switch (ev->type()) {
5141
case QEvent::AccessibilityDescription:
5142
ev->setValue(d->toolTip);
5144
case QEvent::AccessibilityHelp:
5145
ev->setValue(d->whatsThis);
5152
case QEvent::EmbeddingControl:
5153
data->window_flags & ~Qt::WindowType_Mask;
5154
d->topData()->ftop = 0;
5155
d->topData()->fright = 0;
5156
d->topData()->fleft = 0;
5157
d->topData()->fbottom = 0;
5159
case QEvent::ActionAdded:
5160
case QEvent::ActionRemoved:
5161
case QEvent::ActionChanged:
5162
actionEvent((QActionEvent*)e);
5165
return QObject::event(e);
5171
This event handler can be reimplemented to handle state changes.
5173
The state being changed in this event can be retrieved through event \a
5177
void QWidget::changeEvent(QEvent * e)
5180
case QEvent::EnabledChange:
5182
#ifndef QT_NO_ACCESSIBILITY
5183
QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged);
5187
case QEvent::FontChange:
5188
case QEvent::StyleChange:
5193
case QEvent::PaletteChange:
5203
This event handler, for event \a e, can be reimplemented in a
5204
subclass to receive mouse move events for the widget.
5206
If mouse tracking is switched off, mouse move events only occur if
5207
a mouse button is pressed while the mouse is being moved. If mouse
5208
tracking is switched on, mouse move events occur even if no mouse
5211
QMouseEvent::pos() reports the position of the mouse cursor,
5212
relative to this widget. For press and release events, the
5213
position is usually the same as the position of the last mouse
5214
move event, but it might be different if the user's hand shakes.
5215
This is a feature of the underlying window system, not Qt.
5217
\sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
5218
mouseDoubleClickEvent(), event(), QMouseEvent
5221
void QWidget::mouseMoveEvent(QMouseEvent * e)
5227
This event handler, for event \a e, can be reimplemented in a
5228
subclass to receive mouse press events for the widget.
5230
If you create new widgets in the mousePressEvent() the
5231
mouseReleaseEvent() may not end up where you expect, depending on
5232
the underlying window system (or X11 window manager), the widgets'
5233
location and maybe more.
5235
The default implementation implements the closing of popup widgets
5236
when you click outside the window. For other widget types it does
5239
\sa mouseReleaseEvent(), mouseDoubleClickEvent(),
5240
mouseMoveEvent(), event(), QMouseEvent
5243
void QWidget::mousePressEvent(QMouseEvent *e)
5246
if ((windowType() == Qt::Popup)) {
5249
while ((w = qApp->activePopupWidget()) && w != this){
5251
if (qApp->activePopupWidget() == w) // widget does not want to dissappear
5252
w->hide(); // hide at least
5254
if (!rect().contains(e->pos())){
5261
This event handler, for event \a e, can be reimplemented in a
5262
subclass to receive mouse release events for the widget.
5264
\sa mousePressEvent(), mouseDoubleClickEvent(),
5265
mouseMoveEvent(), event(), QMouseEvent
5268
void QWidget::mouseReleaseEvent(QMouseEvent * e)
5274
This event handler, for event \a e, can be reimplemented in a
5275
subclass to receive mouse double click events for the widget.
5277
The default implementation generates a normal mouse press event.
5279
Note that the widgets gets a mousePressEvent() and a
5280
mouseReleaseEvent() before the mouseDoubleClickEvent().
5282
\sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
5283
event(), QMouseEvent
5286
void QWidget::mouseDoubleClickEvent(QMouseEvent *e)
5288
mousePressEvent(e); // try mouse press event
5291
#ifndef QT_NO_WHEELEVENT
5293
This event handler, for event \a e, can be reimplemented in a
5294
subclass to receive wheel events for the widget.
5296
If you reimplement this handler, it is very important that you
5297
\link QWheelEvent ignore()\endlink the event if you do not handle
5298
it, so that the widget's parent can interpret it.
5300
The default implementation ignores the event.
5302
\sa QWheelEvent::ignore(), QWheelEvent::accept(), event(),
5306
void QWidget::wheelEvent(QWheelEvent *e)
5314
This event handler, for event \a e, can be reimplemented in a
5315
subclass to receive tablet events for the widget.
5317
If you reimplement this handler, it is very important that you
5318
\link QTabletEvent ignore()\endlink the event if you do not handle
5319
it, so that the widget's parent can interpret it.
5321
The default implementation ignores the event.
5323
\sa QTabletEvent::ignore(), QTabletEvent::accept(), event(),
5327
void QWidget::tabletEvent(QTabletEvent *e)
5333
This event handler, for event \a e, can be reimplemented in a
5334
subclass to receive key press events for the widget.
5336
A widget must call setFocusPolicy() to accept focus initially and
5337
have focus in order to receive a key press event.
5339
If you reimplement this handler, it is very important that you
5340
\link QKeyEvent ignore()\endlink the event if you do not
5341
understand it, so that the widget's parent can interpret it.
5343
The default implementation closes popup widgets if the user
5344
presses Esc. Otherwise the event is ignored.
5346
\sa keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(),
5347
focusInEvent(), focusOutEvent(), event(), QKeyEvent
5350
void QWidget::keyPressEvent(QKeyEvent *e)
5352
if ((windowType() == Qt::Popup) && e->key() == Qt::Key_Escape) {
5361
This event handler, for event \a e, can be reimplemented in a
5362
subclass to receive key release events for the widget.
5364
A widget must \link setFocusPolicy() accept focus\endlink
5365
initially and \link hasFocus() have focus\endlink in order to
5366
receive a key release event.
5368
If you reimplement this handler, it is very important that you
5369
\link QKeyEvent ignore()\endlink the release if you do not
5370
understand it, so that the widget's parent can interpret it.
5372
The default implementation ignores the event.
5374
\sa keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(),
5375
focusInEvent(), focusOutEvent(), event(), QKeyEvent
5378
void QWidget::keyReleaseEvent(QKeyEvent *e)
5384
\fn void QWidget::focusInEvent(QFocusEvent *event)
5386
This event handler can be reimplemented in a subclass to receive
5387
keyboard focus events (focus received) for the widget. The event
5388
is passed in the \a event parameter
5390
A widget normally must setFocusPolicy() to something other than
5391
\c Qt::NoFocus in order to receive focus events. (Note that the
5392
application programmer can call setFocus() on any widget, even
5393
those that do not normally accept focus.)
5395
The default implementation updates the widget (except for windows
5396
that do not specify a focusPolicy()).
5398
\sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
5399
keyReleaseEvent(), event(), QFocusEvent
5402
void QWidget::focusInEvent(QFocusEvent *)
5404
if (focusPolicy() != Qt::NoFocus || !isWindow()) {
5410
\fn void QWidget::focusOutEvent(QFocusEvent *event)
5412
This event handler can be reimplemented in a subclass to receive
5413
keyboard focus events (focus lost) for the widget. The events is
5414
passed in the \a event parameter.
5416
A widget normally must setFocusPolicy() to something other than
5417
\c Qt::NoFocus in order to receive focus events. (Note that the
5418
application programmer can call setFocus() on any widget, even
5419
those that do not normally accept focus.)
5421
The default implementation updates the widget (except for windows
5422
that do not specify a focusPolicy()).
5424
\sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
5425
keyReleaseEvent(), event(), QFocusEvent
5428
void QWidget::focusOutEvent(QFocusEvent *)
5430
if (focusPolicy() != Qt::NoFocus || !isWindow())
5435
\fn void QWidget::enterEvent(QEvent *event)
5437
This event handler can be reimplemented in a subclass to receive
5438
widget enter events which are passed in the \a event parameter.
5440
An event is sent to the widget when the mouse cursor enters the
5443
\sa leaveEvent(), mouseMoveEvent(), event()
5446
void QWidget::enterEvent(QEvent *)
5451
\fn void QWidget::leaveEvent(QEvent *event)
5453
This event handler can be reimplemented in a subclass to receive
5454
widget leave events which are passed in the \a event parameter.
5456
A leave event is sent to the widget when the mouse cursor leaves
5459
\sa enterEvent(), mouseMoveEvent(), event()
5462
void QWidget::leaveEvent(QEvent *)
5467
\fn void QWidget::paintEvent(QPaintEvent *event)
5469
This event handler can be reimplemented in a subclass to receive
5470
paint events which are passed in the \a event parameter.
5472
A paint event is a request to repaint all or part of the widget.
5473
It can happen as a result of repaint() or update(), or because the
5474
widget was obscured and has now been uncovered, or for many other
5477
Many widgets can simply repaint their entire surface when asked
5478
to, but some slow widgets need to optimize by painting only the
5479
requested region: QPaintEvent::region(). This speed optimization
5480
does not change the result, as painting is clipped to that region
5481
during event processing. QListView and QTableView do this, for
5484
Qt also tries to speed up painting by merging multiple paint
5485
events into one. When update() is called several times or the
5486
window system sends several paint events, Qt merges these events
5487
into one event with a larger region (see QRegion::unite()).
5488
repaint() does not permit this optimization, so we suggest using
5489
update() when possible.
5491
When the paint event occurs, the update region has normally been
5492
erased, so that you're painting on the widget's background.
5494
The background can be set using setBackgroundRole() and
5497
From Qt 4.0, QWidget automatically double-buffers its painting, so
5498
there's no need to write double-buffering code in paintEvent() to
5501
Note: Under X11 it is possible to toggle the global double
5502
buffering by calling \c qt_x11_set_global_double_buffer().
5506
extern void qt_x11_set_global_double_buffer(bool);
5507
qt_x11_set_global_double_buffer(false);
5511
\sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent
5514
void QWidget::paintEvent(QPaintEvent *)
5520
\fn void QWidget::moveEvent(QMoveEvent *event)
5522
This event handler can be reimplemented in a subclass to receive
5523
widget move events which are passed in the \a event parameter.
5524
When the widget receives this event, it is already at the new
5527
The old position is accessible through QMoveEvent::oldPos().
5529
\sa resizeEvent(), event(), move(), QMoveEvent
5532
void QWidget::moveEvent(QMoveEvent *)
5538
\fn void QWidget::resizeEvent(QResizeEvent *event)
5540
This event handler can be reimplemented in a subclass to receive
5541
widget resize events which are passed in the \a event parameter.
5542
When resizeEvent() is called, the widget already has its new
5543
geometry. The old size is accessible through
5544
QResizeEvent::oldSize().
5546
The widget will be erased and receive a paint event immediately
5547
after processing the resize event. No drawing need be (or should
5548
be) done inside this handler.
5551
\sa moveEvent(), event(), resize(), QResizeEvent, paintEvent()
5554
void QWidget::resizeEvent(QResizeEvent *)
5559
\fn void QWidget::actionEvent(QActionEvent *event)
5561
This event handler is called with the given \a event whenever the
5562
widget's actions are changed.
5564
\sa addAction(), insertAction(), removeAction(), actions(), QActionEvent
5566
void QWidget::actionEvent(QActionEvent *)
5572
This event handler, for event \a e, can be reimplemented in a
5573
subclass to receive widget close events.
5575
\sa event(), hide(), close(), QCloseEvent
5578
void QWidget::closeEvent(QCloseEvent *e)
5585
This event handler, for event \a e, can be reimplemented in a
5586
subclass to receive widget context menu events.
5588
The handler is called when the widget's \l contextMenuPolicy is
5589
Qt::DefaultContextMenu.
5591
The default implementation calls e->ignore(), which rejects the
5592
context event. See the \l QContextMenuEvent documentation for
5595
\sa event(), QContextMenuEvent customContextMenuRequested()
5598
void QWidget::contextMenuEvent(QContextMenuEvent *e)
5605
This event handler, for event \a e, can be reimplemented in a
5606
subclass to receive Input Method composition events. This handler
5607
is called when the state of the input method changes.
5609
The default implementation calls e->ignore(), which rejects the
5610
Input Method event. See the \l QInputMethodEvent documentation for more
5613
\sa event(), QInputMethodEvent
5615
void QWidget::inputMethodEvent(QInputMethodEvent *e)
5621
This method is only relevant for input widgets. It is used by the
5622
input method to query a set of properties of the widget to be
5623
able to support complex input method operations as support for
5624
surrounding text and reconversions.
5626
\a query specifies which property is queried.
5628
\sa inputMethodEvent(), QInputMethodEvent, QInputContext
5630
QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const
5633
case Qt::ImMicroFocus:
5634
return QRect(width()/2, 0, 1, height());
5642
#ifndef QT_NO_DRAGANDDROP
5645
\fn void QWidget::dragEnterEvent(QDragEnterEvent *event)
5647
This event handler is called when a drag is in progress and the
5648
mouse enters this widget. The event is passed in the \a event parameter.
5650
See the \link dnd.html Drag-and-drop documentation\endlink for an
5651
overview of how to provide drag-and-drop in your application.
5653
\sa QTextDrag, QImageDrag, QDragEnterEvent
5655
void QWidget::dragEnterEvent(QDragEnterEvent *)
5660
\fn void QWidget::dragMoveEvent(QDragMoveEvent *event)
5662
This event handler is called if a drag is in progress, and when
5663
any of the following conditions occurs: the cursor enters this widget,
5664
the cursor moves within this widget, or a modifier key is pressed on
5665
the keyboard while this widget has the focus. The event is passed
5666
in the \a event parameter.
5668
See the \link dnd.html Drag-and-drop documentation\endlink for an
5669
overview of how to provide drag-and-drop in your application.
5671
\sa QTextDrag, QImageDrag, QDragMoveEvent
5673
void QWidget::dragMoveEvent(QDragMoveEvent *)
5678
\fn void QWidget::dragLeaveEvent(QDragLeaveEvent *event)
5680
This event handler is called when a drag is in progress and the
5681
mouse leaves this widget. The event is passed in the \a event
5684
See the \link dnd.html Drag-and-drop documentation\endlink for an
5685
overview of how to provide drag-and-drop in your application.
5687
\sa QTextDrag, QImageDrag, QDragLeaveEvent
5689
void QWidget::dragLeaveEvent(QDragLeaveEvent *)
5694
\fn void QWidget::dropEvent(QDropEvent *event)
5696
This event handler is called when the drag is dropped on this
5697
widget which are passed in the \a event parameter.
5699
See the \link dnd.html Drag-and-drop documentation\endlink for an
5700
overview of how to provide drag-and-drop in your application.
5702
\sa QTextDrag, QImageDrag, QDropEvent
5704
void QWidget::dropEvent(QDropEvent *)
5708
#endif // QT_NO_DRAGANDDROP
5711
\fn void QWidget::showEvent(QShowEvent *event)
5713
This event handler can be reimplemented in a subclass to receive
5714
widget show events which are passed in the \a event parameter.
5716
Non-spontaneous show events are sent to widgets immediately
5717
before they are shown. The spontaneous show events of windows are
5718
delivered afterwards.
5720
Note: A widget receives spontaneous show and hide events when its
5721
mapping status is changed by the window system, e.g. a spontaneous
5722
hide event when the user minimizes the window, and a spontaneous
5723
show event when the window is restored again. After receiving a
5724
spontaneous hide event, a widget is still considered visible in
5725
the sense of isVisible().
5727
\sa visible, event(), QShowEvent
5729
void QWidget::showEvent(QShowEvent *)
5734
\fn void QWidget::hideEvent(QHideEvent *event)
5736
This event handler can be reimplemented in a subclass to receive
5737
widget hide events. The event is passed in the \a event parameter.
5739
Hide events are sent to widgets immediately after they have been
5742
Note: A widget receives spontaneous show and hide events when its
5743
mapping status is changed by the window system, e.g. a spontaneous
5744
hide event when the user minimizes the window, and a spontaneous
5745
show event when the window is restored again. After receiving a
5746
spontaneous hide event, a widget is still considered visible in
5747
the sense of isVisible().
5749
\sa visible, event(), QHideEvent
5751
void QWidget::hideEvent(QHideEvent *)
5756
\fn QWidget::x11Event(MSG *)
5758
This special event handler can be reimplemented in a subclass to
5759
receive native X11 events.
5761
In your reimplementation of this function, if you want to stop the
5762
event being handled by Qt, return true. If you return false, this
5763
native event is passed back to Qt, which translates the event into
5764
a Qt event and sends it to the widget.
5766
\warning This function is not portable.
5768
\sa QApplication::x11EventFilter()
5772
#if defined(Q_WS_MAC)
5775
\fn bool QWidget::macEvent(EventHandlerCallRef caller, EventRef event)
5777
This special event handler can be reimplemented in a subclass to
5778
receive native Macintosh events which are passed from the \a
5779
caller with the event details in the \a event parameter.
5781
In your reimplementation of this function, if you want to stop the
5782
event being handled by Qt, return true. If you return false, this
5783
native event is passed back to Qt, which translates the event into
5784
a Qt event and sends it to the widget.
5786
\warning This function is not portable.
5788
\sa QApplication::macEventFilter()
5791
bool QWidget::macEvent(EventHandlerCallRef, EventRef)
5797
#if defined(Q_WS_WIN)
5800
This special event handler can be reimplemented in a subclass to
5801
receive native Windows events which are passed in the \a message
5804
In your reimplementation of this function, if you want to stop the
5805
event being handled by Qt, return true and set \a result to the value
5806
that the window procedure should return. If you return false, this
5807
native event is passed back to Qt, which translates the event into
5808
a Qt event and sends it to the widget.
5810
\warning This function is not portable.
5812
\sa QApplication::winEventFilter()
5814
bool QWidget::winEvent(MSG *message, long *result)
5822
#if defined(Q_WS_X11)
5825
\fn bool QWidget::x11Event(XEvent *event)
5827
This special event handler can be reimplemented in a subclass to
5828
receive native X11 events which are passed in the \a event
5831
In your reimplementation of this function, if you want to stop the
5832
event being handled by Qt, return true. If you return false, this
5833
native event is passed back to Qt, which translates the event into
5834
a Qt event and sends it to the widget.
5836
\warning This function is not portable.
5838
\sa QApplication::x11EventFilter()
5840
bool QWidget::x11Event(XEvent *)
5846
#if defined(Q_WS_QWS)
5849
\fn bool QWidget::qwsEvent(QWSEvent *event)
5851
This special event handler can be reimplemented in a subclass to
5852
receive native Qt/Embedded events which are passed in the \a event
5855
In your reimplementation of this function, if you want to stop the
5856
event being handled by Qt, return true. If you return false, this
5857
native event is passed back to Qt, which translates the event into
5858
a Qt event and sends it to the widget.
5860
\warning This function is not portable.
5862
\sa QApplication::qwsEventFilter()
5864
bool QWidget::qwsEvent(QWSEvent *)
5873
Ensures that the widget has been polished by QStyle (i.e., has a
5874
proper font and palette).
5876
QWidget calls this function after it has been fully constructed but
5877
before it is shown the very first time. You can call this function if you
5878
want to ensure that the widget is polished before doing an operation
5879
(e.g., the correct font size might be needed in the widget's sizeHint()
5882
Polishing is useful for final initialization that must happen after
5883
all constructors (from base classes as well as from subclasses)
5886
If you need to change some settings when a widget is polished,
5887
reimplement event() and handle the QEvent::Polish event type.
5889
Note: The function is declared const so that it can be called from
5890
other const functions (e.g., sizeHint()).
5894
void QWidget::ensurePolished() const
5898
const QMetaObject *m = metaObject();
5899
if (m == d->polished)
5903
QEvent e(QEvent::Polish);
5904
QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e);
5906
// polish children after 'this'
5907
QList<QObject*> children = d->children;
5908
for (int i = 0; i < children.size(); ++i) {
5909
QObject *o = children.at(i);
5910
if(!o->isWidgetType())
5912
if (QWidget *w = qobject_cast<QWidget *>(o))
5913
w->ensurePolished();
5916
if (d->parent && d->sendChildEvents) {
5917
QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this));
5918
QCoreApplication::sendEvent(d->parent, &e);
5923
Returns the mask currently set on a widget. If no mask is set the
5924
return value will be an empty region.
5926
\sa setMask(), clearMask(), QRegion::isEmpty()
5928
QRegion QWidget::mask() const
5931
return d->extra ? d->extra->mask : QRegion();
5934
#ifndef QT_NO_LAYOUT
5936
Returns the layout engine that manages the geometry of this
5939
If the widget does not have a layout, layout() returns 0.
5941
\sa setLayout(), sizePolicy()
5943
QLayout* QWidget::layout() const
5945
return d_func()->layout;
5950
Sets the layout engine for this widget to \a l.
5952
There can be only one top-level layout for a widget.
5957
void QWidget::setLayout(QLayout *l)
5960
qWarning("cannot set layout to 0");
5965
qWarning("QWidget::setLayout() : QLayout \"%s\" added to %s \"%s\", which already has a"
5966
" layout", l->objectName().toLocal8Bit().data(), metaObject()->className(),
5967
objectName().toLocal8Bit().data());
5970
l->d_func()->topLevel = true;
5971
d_func()->layout = l;
5972
if (l->parent() != this) {
5974
l->d_func()->reparentChildWidgets(this);
5983
\property QWidget::sizePolicy
5984
\brief the default layout behavior of the widget
5986
If there is a QLayout that manages this widget's children, the
5987
size policy specified by that layout is used. If there is no such
5988
QLayout, the result of this function is used.
5990
The default policy is Preferred/Preferred, which means that the
5991
widget can be freely resized, but prefers to be the size
5992
sizeHint() returns. Button-like widgets set the size policy to
5993
specify that they may stretch horizontally, but are fixed
5994
vertically. The same applies to lineedit controls (such as
5995
QLineEdit, QSpinBox or an editable QComboBox) and other
5996
horizontally orientated widgets (such as QProgressBar).
5997
QToolButton's are normally square, so they allow growth in both
5998
directions. Widgets that support different directions (such as
5999
QSlider, QScrollBar or QHeader) specify stretching in the
6000
respective direction only. Widgets that can provide scrollbars
6001
(usually subclasses of QScrollView) tend to specify that they can
6002
use additional space, and that they can make do with less than
6005
\sa sizeHint() QLayout QSizePolicy updateGeometry()
6007
QSizePolicy QWidget::sizePolicy() const
6010
// GCC 2.95.x on FreeBSD can't handle this as a turnary operator.
6012
return d->extra->size_policy;
6013
return QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
6016
void QWidget::setSizePolicy(QSizePolicy policy)
6018
setAttribute(Qt::WA_WState_OwnSizePolicy);
6019
if (policy == sizePolicy())
6024
d->extra->size_policy = policy;
6029
\fn void QWidget::setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
6032
Sets the size policy of the widget to \a horizontal and \a
6033
vertical, with standard stretch and no height-for-width.
6035
\sa QSizePolicy::QSizePolicy()
6039
Returns the preferred height for this widget, given the width \a w.
6041
If this widget has a layout, the default implementation returns
6042
the layout's preferred height. if there is no layout, the default
6043
implementation returns -1 indicating that the preferred height
6044
does not depend on the width.
6047
int QWidget::heightForWidth(int w) const
6049
#ifndef QT_NO_LAYOUT
6050
if (layout() && layout()->hasHeightForWidth())
6051
return layout()->totalHeightForWidth(w);
6057
\fn QWidget *QWidget::childAt(int x, int y) const
6059
Returns the visible child widget at the position (\a{x}, \a{y})
6060
in the widget's coordinate system. If there is no visible child
6061
widget at the specified position, the function returns 0.
6067
Returns the visible child widget at point \a p in the widget's own
6071
QWidget *QWidget::childAt(const QPoint &p) const
6073
if (!rect().contains(p))
6076
for (int i = d->children.size(); i > 0 ;) {
6078
QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
6079
if (w && !w->isWindow() && !w->isHidden() && w->geometry().contains(p)) {
6080
if (w->testAttribute(Qt::WA_TransparentForMouseEvents))
6082
if (QWidget *t = w->childAt(p.x() - w->x(), p.y() - w->y()))
6084
// if WMouseNoMask is set the widget mask is ignored, if
6085
// the widget has no mask then the WMouseNoMask flag has no
6087
if (w->testAttribute(Qt::WA_MouseNoMask) || w->mask().contains(p)
6088
|| w->mask().isEmpty())
6097
Notifies the layout system that this widget has changed and may
6098
need to change geometry.
6100
Call this function if the sizeHint() or sizePolicy() have changed.
6102
For explicitly hidden widgets, updateGeometry() is a no-op. The
6103
layout system will be notified as soon as the widget is shown.
6106
void QWidget::updateGeometry()
6108
#ifndef QT_NO_LAYOUT
6109
if (!isWindow() && !isHidden() && parentWidget()) {
6110
if (parentWidget()->d_func()->layout)
6111
parentWidget()->d_func()->layout->invalidate();
6112
else if (parentWidget()->isVisible())
6113
QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest));
6118
/*! \property QWidget::windowFlags
6120
Window flags are a combination of a type (e.g. Qt::Dialog) and
6121
zero or more hints to the window system (e.g.
6122
Qt::FramelessWindowHint).
6124
If the widget had type Qt::Widget or Qt::SubWindow and becomes a
6125
window (Qt::Window, Qt::Dialog, etc.), it is put at position (0,
6126
0) on the desktop. If the widget is a window and becomes a
6127
Qt::Widget or Qt::SubWindow, it is put at position (0, 0)
6128
relative to its parent widget.
6132
void QWidget::setWindowFlags(Qt::WindowFlags flags)
6134
if (data->window_flags == flags)
6137
if ((data->window_flags | flags) & Qt::Window) {
6138
// the old type was a window and/or the new type is a window
6139
QPoint oldPos = pos();
6140
setParent(parentWidget(), flags);
6142
// if both types are windows or neither of them are, we restore
6144
if (!((data->window_flags ^ flags) & Qt::Window))
6147
data->window_flags = flags;
6152
Sets the window flags for the widget to \a flags,
6153
\e without telling the window system.
6155
\warning Do not call this function unless you really know what
6158
\sa setWindowFlags()
6160
void QWidget::overrideWindowFlags(Qt::WindowFlags flags)
6162
data->window_flags = flags;
6166
\fn Qt::WindowType QWidget::windowType() const
6168
Returns the window type of this widget. This is identical to
6169
windowFlags() & Qt::WindowType_Mask.
6175
Sets the parent of the widget to \a parent. The widget is moved
6176
to position (0, 0) in its new parent.
6178
If the new parent widget is in a different window, the
6179
reparented widget and its children are appended to the end of the
6180
\l{setFocusPolicy()}{tab chain} of the new parent
6181
widget, in the same internal order as before. If one of the moved
6182
widgets had keyboard focus, setParent() calls clearFocus() for that
6185
If the new parent widget is in the same window as the
6186
old parent, setting the parent doesn't change the tab order or
6189
If the "new" parent widget is the old parent widget, this function
6192
\warning It is very unlikely that you will ever need this
6193
function. If you have a widget that changes its content
6194
dynamically, it is far easier to use \l QStackedWidget.
6196
\sa setWindowFlags()
6198
void QWidget::setParent(QWidget *parent)
6200
if (parent == parentWidget())
6202
setParent((QWidget*)parent, windowFlags() & ~Qt::WindowType_Mask);
6208
This function also takes widget flags, \a f as an argument.
6211
void QWidget::setParent(QWidget *parent, Qt::WFlags f)
6214
bool resized = testAttribute(Qt::WA_Resized);
6215
QWidget *oldtlw = window();
6216
bool newParent = (parent != parentWidget());
6219
QEvent e(QEvent::ParentAboutToChange);
6220
QApplication::sendEvent(this, &e);
6223
d->setParent_sys(parent, f);
6224
d->reparentFocusWidgets(oldtlw);
6225
setAttribute(Qt::WA_Resized, resized);
6227
d->resolvePalette();
6228
d->resolveLayoutDirection();
6231
// send and post remaining QObject events
6232
if (parent && d->sendChildEvents) {
6233
QChildEvent e(QEvent::ChildAdded, this);
6234
QApplication::sendEvent(parent, &e);
6236
QApplication::postEvent(parent, new QChildEvent(QEvent::ChildInserted, this));
6240
if (parent && d->sendChildEvents && d->polished) {
6241
QChildEvent e(QEvent::ChildPolished, this);
6242
QCoreApplication::sendEvent(parent, &e);
6244
QEvent e(QEvent::ParentChange);
6245
QApplication::sendEvent(this, &e);
6250
Repaints the widget directly by calling paintEvent() immediately,
6251
unless updates are disabled or the widget is hidden.
6253
We suggest only using repaint() if you need an immediate repaint,
6254
for example during animation. In almost all circumstances update()
6255
is better, as it permits Qt to optimize for speed and minimize
6258
\warning If you call repaint() in a function which may itself be
6259
called from paintEvent(), you may get infinite recursion. The
6260
update() function never causes recursion.
6262
\sa update(), paintEvent(), setUpdatesEnabled()
6265
void QWidget::repaint()
6268
#if defined(Q_WS_X11)
6269
// d->removePendingPaintEvents(); // ### this is far too slow to go in
6271
repaint(d->clipRect());
6276
This version repaints a rectangle (\a x, \a y, \a w, \a h) inside
6279
If \a w is negative, it is replaced with \c{width() - x}, and if
6280
\a h is negative, it is replaced width \c{height() - y}.
6282
void QWidget::repaint(int x, int y, int w, int h)
6284
if (x > data->crect.width() || y > data->crect.height())
6289
w = data->crect.width() - x;
6291
h = data->crect.height() - y;
6292
repaint(d->clipRect().intersect(QRect(x, y, w, h)));
6297
This version repaints a rectangle \a r inside the widget.
6299
void QWidget::repaint(const QRect &r)
6302
repaint(QRegion(d->clipRect().intersect(r)));
6305
/*! \fn void QWidget::repaint(const QRegion &rgn)
6308
This version repaints a region \a rgn inside the widget.
6311
/*! \fn void QWidget::update()
6312
Updates the widget unless updates are disabled or the widget is
6315
This function does not cause an immediate repaint; instead it
6316
schedules a paint event for processing when Qt returns to the main
6317
event loop. This permits Qt to optimize for more speed and less
6318
flicker than a call to repaint() does.
6320
Calling update() several times normally results in just one
6323
Qt normally erases the widget's area before the paintEvent() call.
6324
If the \c Qt::WRepaintNoErase widget flag is set, the widget is
6325
responsible for painting all its pixels itself.
6327
\sa repaint() paintEvent(), setUpdatesEnabled()
6330
/*! \fn void QWidget::update(int x, int y, int w, int h)
6333
This version updates a rectangle (\a x, \a y, \a w, \a h) inside
6339
\fn void QWidget::update(const QRect &r)
6342
This version updates a rectangle \a r inside the widget.
6345
/*! \fn void QWidget::update(const QRegion &rgn)
6348
This version repaints a region \a rgn inside the widget.
6353
Clear the rectangle at point (\a x, \a y) of width \a w and height
6356
\warning This is best done in a paintEvent().
6358
void QWidget::erase_helper(int x, int y, int w, int h)
6360
if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible))
6363
w = data->crect.width() - x;
6365
h = data->crect.height() - y;
6366
if (w != 0 && h != 0) {
6368
p.eraseRect(QRect(x, y, w, h));
6375
Clear the given region, \a rgn.
6377
Drawing may only take place in a QPaintEvent. Overload
6378
paintEvent() to do your erasing and call update() to schedule a
6379
replaint whenever necessary. See also QPainter.
6381
void QWidget::erase(const QRegion& rgn)
6383
if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible))
6387
p.setClipRegion(rgn);
6388
p.eraseRect(rgn.boundingRect());
6391
void QWidget::drawText_helper(int x, int y, const QString &str)
6393
if(!testAttribute(Qt::WA_WState_Visible))
6395
QPainter paint(this);
6396
paint.drawText(x, y, str);
6403
Use the no-argument overload instead.
6405
bool QWidget::close(bool alsoDelete)
6407
QPointer<QWidget> that = this;
6408
bool accepted = close();
6409
if (alsoDelete && accepted && that)
6414
void QWidget::setIcon(const QPixmap &i)
6420
Return's the widget's icon.
6422
Use windowIconText() instead().
6424
const QPixmap *QWidget::icon() const
6427
return (d->extra && d->extra->topextra) ? d->extra->topextra->iconPixmap : 0;
6430
#endif // QT3_SUPPORT
6433
Sets the attribute \a attribute on this widget if \a on is true;
6434
otherwise clears the attribute.
6438
void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
6441
Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
6442
"QWidget::setAttribute(WidgetAttribute, bool)",
6443
"QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
6444
if (attribute < int(8*sizeof(uint))) {
6446
data->widget_attributes |= (1<<attribute);
6448
data->widget_attributes &= ~(1<<attribute);
6450
const int x = attribute - 8*sizeof(uint);
6451
const int int_off = x / (8*sizeof(uint));
6453
d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
6455
d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
6457
switch (attribute) {
6458
case Qt::WA_NoChildEventsForParent:
6459
d->sendChildEvents = !on;
6461
case Qt::WA_NoChildEventsFromChildren:
6462
d->receiveChildEvents = !on;
6464
case Qt::WA_MacMetalStyle:
6466
extern void qt_mac_update_metal_style(QWidget*); //qwidget_mac.cpp
6467
qt_mac_update_metal_style(this);
6470
case Qt::WA_MouseTracking: {
6471
QEvent e(QEvent::MouseTrackingChange);
6472
QApplication::sendEvent(this, &e);
6474
case Qt::WA_NoSystemBackground:
6475
case Qt::WA_UpdatesDisabled:
6476
d->updateSystemBackground();
6478
case Qt::WA_TransparentForMouseEvents:
6480
extern void qt_mac_update_ignore_mouseevents(QWidget*); //qwidget_mac.cpp
6481
qt_mac_update_ignore_mouseevents(this);
6484
case Qt::WA_ContentsPropagated:
6486
d->updatePropagatedBackground();
6489
case Qt::WA_InputMethodEnabled:
6490
QWinInputContext::enable(this, on);
6498
/*! \fn bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const
6500
Returns true if attribute \a attribute is set on this widget;
6501
otherwise returns false.
6505
bool QWidget::testAttribute_helper(Qt::WidgetAttribute attribute) const
6508
const int x = attribute - 8*sizeof(uint);
6509
const int int_off = x / (8*sizeof(uint));
6510
return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint)))));
6514
\property QWidget::windowOpacity
6516
\brief The level of opacity for the window.
6518
The valid range of opacity is from 1.0 (completely opaque) to
6519
0.0 (completely transparent).
6521
By default the value of this property is 1.0.
6523
This feature is only present on Mac OS X and Windows 2000 and up.
6525
\warning Changing this property from opaque to transparent might issue a
6526
paint event that needs to be processed before the window is displayed
6527
correctly. This affects mainly the use of QPixmap::grabWindow(). Also note
6528
that semi-transparent windows update and resize significantly slower than
6533
\property QWidget::windowModified
6534
\brief whether the document shown in the window has unsaved changes
6536
A modified window is a window whose content has changed but has
6537
not been saved to disk. This flag will have different effects
6538
varied by the platform. On Mac OS X the close button will have a
6539
modified look; on other platforms, the window title will have an
6542
The window title must contain a "[*]" placeholder, which
6543
indicates where the '*' should appear. Normally, it should appear
6544
right after the file name (e.g., "document1.txt[*] - Text
6545
Editor"). If the window isn't modified, the placeholder is simply
6550
bool QWidget::isWindowModified() const
6552
return testAttribute(Qt::WA_WindowModified);
6555
void QWidget::setWindowModified(bool mod)
6558
setAttribute(Qt::WA_WindowModified, mod);
6560
if (!windowTitle().contains("[*]") && mod)
6561
qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder!");
6562
d->setWindowTitle_helper(windowTitle());
6563
d->setWindowIconText_helper(windowIconText());
6565
d->setWindowModified_sys(mod);
6568
QEvent e(QEvent::ModifiedChange);
6569
QApplication::sendEvent(this, &e);
6573
\property QWidget::toolTip
6575
\brief the widget's tooltip
6577
\sa QToolTip statusTip whatsThis
6579
void QWidget::setToolTip(const QString &s)
6585
QString QWidget::toolTip() const
6592
\property QWidget::statusTip
6594
\brief the widget's status tip
6596
\sa toolTip whatsThis
6598
void QWidget::setStatusTip(const QString &s)
6604
QString QWidget::statusTip() const
6607
return d->statusTip;
6611
\property QWidget::whatsThis
6613
\brief the widget's What's This help text.
6615
\sa QWhatsThis QWidget::toolTip QWidget::statusTip
6617
void QWidget::setWhatsThis(const QString &s)
6623
QString QWidget::whatsThis() const
6626
return d->whatsThis;
6629
#ifndef QT_NO_ACCESSIBILITY
6631
\property QWidget::accessibleName
6633
\brief the widget's name as seen by assistive technologies
6635
\sa QAccessibleInterface::text()
6637
void QWidget::setAccessibleName(const QString &name)
6640
d->accessibleName = name;
6643
QString QWidget::accessibleName() const
6646
return d->accessibleName;
6650
\property QWidget::accessibleDescription
6652
\brief the widget's description as seen by assistive technologies
6654
\sa QAccessibleInterface::text()
6656
void QWidget::setAccessibleDescription(const QString &description)
6659
d->accessibleDescription = description;
6662
QString QWidget::accessibleDescription() const
6665
return d->accessibleDescription;
6670
Adds a shortcut to Qt's shortcut system that watches for the given
6671
\a key sequence in the given \a context. If the \a context is not
6672
\c OnApplication, the shortcut is local to this widget; otherwise
6673
it applies to the application as a whole.
6675
If the same \a key sequence has been grabbed by several widgets,
6676
when the \a key sequence occurs a QEvent::Shortcut event is sent
6677
to all the widgets to which it applies in a non-deterministic
6678
order, but with the ``ambiguous'' flag set to true.
6680
\warning You should not normally need to use this function;
6681
instead create \l{QAction}s with the shortcut key sequences you
6682
require (if you also want equivalent menu options and toolbar
6683
buttons), or create \l{QShortcut}s if you just need key sequences.
6684
Both QAction and QShortcut handle all the event filtering for you,
6685
and provide signals which are triggered when the user triggers the
6686
key sequence, so are much easier to use than this low-level
6689
\sa releaseShortcut() setShortcutEnabled()
6691
int QWidget::grabShortcut(const QKeySequence &key, Qt::ShortcutContext context)
6696
setAttribute(Qt::WA_GrabbedShortcut);
6697
return qApp->d_func()->shortcutMap.addShortcut(this, key, context);
6702
Removes the shortcut with the given \a id from Qt's shortcut
6703
system. The widget will no longer receive QEvent::Shortcut events
6704
for the shortcut's key sequence (unless it has other shortcuts
6705
with the same key sequence).
6707
\warning You should not normally need to use this function since
6708
Qt's shortcut system removes shortcuts automatically when their
6709
parent widget is destroyed. It is best to use QAction or
6710
QShortcut to handle shortcuts, since they are easier to use than
6711
this low-level function. Note also that this is an expensive
6714
\sa grabShortcut() setShortcutEnabled()
6716
void QWidget::releaseShortcut(int id)
6720
qApp->d_func()->shortcutMap.removeShortcut(id, this, 0);
6724
If \a enable is true, the shortcut with the given \a id is
6725
enabled; otherwise the shortcut is disabled.
6727
\warning You should not normally need to use this function since
6728
Qt's shortcut system enables/disables shortcuts automatically as
6729
widgets become hidden/visible and gain or lose focus. It is best
6730
to use QAction or QShortcut to handle shortcuts, since they are
6731
easier to use than this low-level function.
6733
\sa grabShortcut() releaseShortcut()
6735
void QWidget::setShortcutEnabled(int id, bool enable)
6739
qApp->d_func()->shortcutMap.setShortcutEnabled(enable, id, this, 0);
6744
Updates the widget's micro focus.
6748
void QWidget::updateMicroFocus()
6750
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
6751
QInputContext *ic = inputContext();
6755
#ifndef QT_NO_ACCESSIBILITY
6756
// ##### is this correct
6757
QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged);
6762
#if defined (Q_WS_WIN)
6764
Returns the window system handle of the widget, for low-level
6765
access. Using this function is not portable.
6767
An HDC aquired with getDC() has to be released with releaseDC().
6769
\warning Using this function is not portable.
6771
HDC QWidget::getDC() const
6778
Releases the HDC \a hdc aquired by a previous call to getDC().
6780
\warning Using this function is not portable.
6782
void QWidget::releaseDC(HDC hdc) const
6785
Q_ASSERT(d->hd == hdc);
6789
Returns the window system handle of the widget, for low-level
6790
access. Using this function is not portable.
6792
The HANDLE type varies with platform; see \c qwindowdefs.h for
6795
Qt::HANDLE QWidget::handle() const
6804
Raises this widget to the top of the parent widget's stack.
6806
After this call the widget will be visually in front of any
6807
overlapping sibling widgets.
6809
\sa lower(), stackUnder()
6812
void QWidget::raise()
6815
QWidget *p = parentWidget();
6817
if (p && (from = p->d_func()->children.indexOf(this)) >= 0)
6818
p->d_func()->children.move(from, p->d_func()->children.size() - 1);
6821
QEvent e(QEvent::ZOrderChange);
6822
QApplication::sendEvent(this, &e);
6826
Lowers the widget to the bottom of the parent widget's stack.
6828
After this call the widget will be visually behind (and therefore
6829
obscured by) any overlapping sibling widgets.
6831
\sa raise(), stackUnder()
6834
void QWidget::lower()
6837
QWidget *p = parentWidget();
6839
if (p && (from = p->d_func()->children.indexOf(this)) >= 0)
6840
p->d_func()->children.move(from, 0);
6843
QEvent e(QEvent::ZOrderChange);
6844
QApplication::sendEvent(this, &e);
6849
Places the widget under \a w in the parent widget's stack.
6851
To make this work, the widget itself and \a w must be siblings.
6853
\sa raise(), lower()
6855
void QWidget::stackUnder(QWidget* w)
6858
QWidget *p = parentWidget();
6861
if (!w || isWindow() || p != w->parentWidget() || this == w)
6863
if (p && (to = p->d_func()->children.indexOf(w)) >= 0 && (from = p->d_func()->children.indexOf(this)) >= 0) {
6866
p->d_func()->children.move(from, to);
6868
d->stackUnder_sys(w);
6870
QEvent e(QEvent::ZOrderChange);
6871
QApplication::sendEvent(this, &e);
6874
void QWidget::styleChange(QStyle&) { }
6875
void QWidget::enabledChange(bool) { } // compat
6876
void QWidget::paletteChange(const QPalette &) { } // compat
6877
void QWidget::fontChange(const QFont &) { } // compat
6878
void QWidget::windowActivationChange(bool) { } // compat
6879
void QWidget::languageChange() { } // compat
6883
\property QWidget::visibleRect
6884
\brief holds the widget's visible rectangle
6890
\enum QWidget::BackgroundOrigin
6897
\value AncestorOrigin
6902
\fn bool QWidget::isVisibleToTLW() const
6904
Use isVisible() instead.
6908
\fn void QWidget::iconify()
6910
Use showMinimized() instead.
6914
\fn void QWidget::constPolish() const
6916
Use ensurePolished() instead.
6920
\fn void QWidget::reparent(QWidget *parent, Qt::WFlags f, const QPoint &p, bool showIt)
6922
Use setParent() to change the parent or the widget's widget flags;
6923
use move() to move the widget, and use show() to show the widget.
6927
\fn void QWidget::reparent(QWidget *parent, const QPoint &p, bool showIt)
6929
Use setParent() to change the parent; use move() to move the
6930
widget, and use show() to show the widget.
6934
\fn void QWidget::recreate(QWidget *parent, Qt::WFlags f, const QPoint & p, bool showIt)
6936
Use setParent() to change the parent or the widget's widget flags;
6937
use move() to move the widget, and use show() to show the widget.
6941
\fn bool QWidget::hasMouse() const
6943
Use testAttribute(Qt::WA_UnderMouse) instead.
6947
\fn bool QWidget::ownCursor() const
6949
Use testAttribute(Qt::WA_SetCursor) instead.
6953
\fn bool QWidget::ownFont() const
6955
Use testAttribute(Qt::WA_SetFont) instead.
6959
\fn void QWidget::unsetFont()
6961
Use setFont(QFont()) instead.
6965
\fn bool QWidget::ownPalette() const
6967
Use testAttribute(Qt::WA_SetPalette) instead.
6971
\fn void QWidget::unsetPalette()
6973
Use setPalette(QPalette()) instead.
6977
\fn void QWidget::setEraseColor(const QColor &color)
6979
Use the palette instead.
6982
widget->setEraseColor(color);
6985
palette.setColor(widget->backgroundRole(), color);
6986
widget->setPalette(palette);
6991
\fn void QWidget::setErasePixmap(const QPixmap &pixmap)
6993
Use the palette instead.
6996
widget->setErasePixmap(pixmap);
6999
palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
7000
widget->setPalette(palette);
7005
\fn void QWidget::setPaletteForegroundColor(const QColor &color)
7007
Use the palette directly.
7010
widget->setPaletteForegroundColor(color);
7013
palette.setColor(widget->foregroundRole(), color);
7014
widget->setPalette(palette);
7019
\fn void QWidget::setPaletteBackgroundColor(const QColor &color)
7021
Use the palette directly.
7024
widget->setPaletteBackgroundColor(color);
7027
palette.setColor(widget->backgroundRole(), color);
7028
widget->setPalette(palette);
7033
\fn void QWidget::setPaletteBackgroundPixmap(const QPixmap &pixmap)
7035
Use the palette directly.
7038
widget->setPaletteBackgroundPixmap(pixmap);
7041
palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
7042
widget->setPalette(palette);
7047
\fn void QWidget::setBackgroundPixmap(const QPixmap &pixmap)
7049
Use the palette instead.
7052
widget->setBackgroundPixmap(pixmap);
7055
palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
7056
widget->setPalette(palette);
7061
\fn void QWidget::setBackgroundColor(const QColor &color)
7063
Use the palette instead.
7066
widget->setBackgroundColor(color);
7069
palette.setColor(widget->backgroundRole(), color);
7070
widget->setPalette(palette);
7075
\fn QColorGroup QWidget::colorGroup() const
7077
Use QColorGroup(palette()) instead.
7081
\fn QWidget *QWidget::parentWidget(bool sameWindow) const
7083
Use the no-argument overload instead.
7087
\fn void QWidget::setKeyCompression(bool b)
7089
Use setAttribute(Qt::WA_KeyCompression, b) instead.
7093
\fn void QWidget::setFont(const QFont &f, bool b)
7095
Use the single-argument overload instead.
7099
\fn void QWidget::setPalette(const QPalette &p, bool b)
7101
Use the single-argument overload instead.
7105
\fn void QWidget::setBackgroundOrigin(BackgroundOrigin background)
7111
\fn BackgroundOrigin QWidget::backgroundOrigin() const
7115
Always returns \c WindowOrigin.
7119
\fn QPoint QWidget::backgroundOffset() const
7123
Always returns QPoint().
7127
\fn void QWidget::repaint(bool b)
7129
The boolean parameter \a b is ignored. Use the no-argument overload instead.
7133
\fn void QWidget::repaint(int x, int y, int w, int h, bool b)
7135
The boolean parameter \a b is ignored. Use the four-argument overload instead.
7139
\fn void QWidget::repaint(const QRect &r, bool b)
7141
The boolean parameter \a b is ignored. Use the single rect-argument overload instead.
7145
\fn void QWidget::repaint(const QRegion &rgn, bool b)
7147
The boolean parameter \a b is ignored. Use the single region-argument overload instead.
7151
\fn void QWidget::erase()
7153
Drawing may only take place in a QPaintEvent. Overload
7154
paintEvent() to do your erasing and call update() to schedule a
7155
replaint whenever necessary. See also QPainter.
7159
\fn void QWidget::erase(int x, int y, int w, int h)
7161
Drawing may only take place in a QPaintEvent. Overload
7162
paintEvent() to do your erasing and call update() to schedule a
7163
replaint whenever necessary. See also QPainter.
7167
\fn void QWidget::erase(const QRect &rect)
7169
Drawing may only take place in a QPaintEvent. Overload
7170
paintEvent() to do your erasing and call update() to schedule a
7171
replaint whenever necessary. See also QPainter.
7175
\fn void QWidget::drawText(const QPoint &p, const QString &s)
7177
Drawing may only take place in a QPaintEvent. Overload
7178
paintEvent() to do your drawing and call update() to schedule a
7179
replaint whenever necessary. See also QPainter.
7183
\fn void QWidget::drawText(int x, int y, const QString &s)
7185
Drawing may only take place in a QPaintEvent. Overload
7186
paintEvent() to do your drawing and call update() to schedule a
7187
replaint whenever necessary. See also QPainter.
7191
\fn QWidget *QWidget::childAt(const QPoint &p, bool includeThis) const
7193
Use the single point argument overload instead.
7197
\fn void QWidget::setCaption(const QString &c)
7199
Use setWindowTitle() instead.
7203
\fn void QWidget::setIcon(const QPixmap &i)
7205
Use setWindowIcon() instead.
7209
\fn void QWidget::setIconText(const QString &it)
7211
Use setWindowIconText() instead.
7215
\fn QString QWidget::caption() const
7217
Use windowTitle() instead.
7221
\fn QString QWidget::iconText() const
7223
Use windowIconText() instead().
7227
\fn bool QWidget::isTopLevel() const
7230
Use isWindow() instead.
7234
\fn bool QWidget::isRightToLeft() const
7239
\fn bool QWidget::isLeftToRight() const
7244
\fn void QWidget::setInputMethodEnabled(bool enabled)
7246
Use setAttribute(Qt::WA_InputMethodEnabled, \a enabled) instead.
7250
\fn bool QWidget::isInputMethodEnabled() const
7252
Use testAttribute(Qt::WA_InputMethodEnabled) instead.
7256
\fn void QWidget::setActiveWindow()
7258
Use activateWindow() instead.
7262
\fn bool QWidget::isShown() const
7264
Use !isHidden() instead (notice the exclamation mark), or use isVisible() to check whether the widget is visible.
7268
\fn bool QWidget::isDialog() const
7270
Use windowType() == Qt::Dialog instead.
7274
\fn bool QWidget::isPopup() const
7276
Use windowType() == Qt::Popup instead.
7280
\fn bool QWidget::isDesktop() const
7282
Use windowType() == Qt::Desktop instead.
7286
\fn void QWidget::polish()
7288
Use ensurePolished() instead.
7292
\fn QWidget *QWidget::childAt(int x, int y, bool includeThis) const
7294
Use the childAt() overload that doesn't have an \a includeThis parameter.
7297
return widget->childAt(x, y, true);
7299
QWidget *child = widget->childAt(x, y, true);
7302
if (widget->rect().contains(x, y))
7308
\fn void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw)
7311
Use the \l sizePolicy property and heightForWidth() function instead.
7315
\fn bool QWidget::isUpdatesEnabled() const
7318
Use the \l updatesEnabled property instead.
7321
#include "moc_qwidget.cpp"