1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #ifndef QT_NO_GRAPHICSVIEW
46 #include "qgraphicswidget.h"
47 #include "qgraphicswidget_p.h"
48 #include "qgraphicslayout.h"
49 #include "qgraphicslayout_p.h"
50 #include "qgraphicsscene.h"
51 #include "qgraphicssceneevent.h"
54 #include <private/qaction_p.h>
56 #include <private/qapplication_p.h>
57 #include <private/qgraphicsscene_p.h>
58 #ifndef QT_NO_SHORTCUT
59 #include <private/qshortcutmap_p.h>
61 #include <QtCore/qmutex.h>
62 #include <QtWidgets/qapplication.h>
63 #include <QtWidgets/qgraphicsview.h>
64 #include <QtWidgets/qgraphicsproxywidget.h>
65 #include <QtGui/qpalette.h>
66 #include <QtWidgets/qstyleoption.h>
73 \class QGraphicsWidget
74 \brief The QGraphicsWidget class is the base class for all widget
75 items in a QGraphicsScene.
77 \ingroup graphicsview-api
79 QGraphicsWidget is an extended base item that provides extra functionality
80 over QGraphicsItem. It is similar to QWidget in many ways:
83 \o Provides a \l palette, a \l font and a \l style().
84 \o Has a defined geometry().
85 \o Supports layouts with setLayout() and layout().
86 \o Supports shortcuts and actions with grabShortcut() and insertAction()
89 Unlike QGraphicsItem, QGraphicsWidget is not an abstract class; you can
90 create instances of a QGraphicsWidget without having to subclass it.
91 This approach is useful for widgets that only serve the purpose of
92 organizing child widgets into a layout.
94 QGraphicsWidget can be used as a base item for your own custom item if
95 you require advanced input focus handling, e.g., tab focus and activation, or
98 Since QGraphicsWidget resembles QWidget and has similar API, it is
99 easier to port a widget from QWidget to QGraphicsWidget, instead of
102 \note QWidget-based widgets can be directly embedded into a
103 QGraphicsScene using QGraphicsProxyWidget.
105 Noticeable differences between QGraphicsWidget and QWidget are:
108 \header \o QGraphicsWidget
110 \row \o Coordinates and geometry are defined with qreals (doubles or
111 floats, depending on the platform).
112 \o QWidget uses integer geometry (QPoint, QRect).
113 \row \o The widget is already visible by default; you do not have to
114 call show() to display the widget.
115 \o QWidget is hidden by default until you call show().
116 \row \o A subset of widget attributes are supported.
117 \o All widget attributes are supported.
118 \row \o A top-level item's style defaults to QGraphicsScene::style
119 \o A top-level widget's style defaults to QApplication::style
120 \row \o Graphics View provides a custom drag and drop framework, different
122 \o Standard drag and drop framework.
123 \row \o Widget items do not support modality.
124 \o Full modality support.
127 QGraphicsWidget supports a subset of Qt's widget attributes,
128 (Qt::WidgetAttribute), as shown in the table below. Any attributes not
129 listed in this table are unsupported, or otherwise unused.
132 \header \o Widget Attribute \o Usage
133 \row \o Qt::WA_SetLayoutDirection
134 \o Set by setLayoutDirection(), cleared by
135 unsetLayoutDirection(). You can test this attribute to
136 check if the widget has been explicitly assigned a
137 \l{QGraphicsWidget::layoutDirection()}
138 {layoutDirection}. If the attribute is not set, the
139 \l{QGraphicsWidget::layoutDirection()}
140 {layoutDirection()} is inherited.
141 \row \o Qt::WA_RightToLeft
142 \o Toggled by setLayoutDirection(). Inherited from the
143 parent/scene. If set, the widget's layout will order
144 horizontally arranged widgets from right to left.
145 \row \o Qt::WA_SetStyle
146 \o Set and cleared by setStyle(). If this attribute is
147 set, the widget has been explicitly assigned a style.
148 If it is unset, the widget will use the scene's or the
150 \row \o Qt::WA_Resized
151 \o Set by setGeometry() and resize().
152 \row \o Qt::WA_SetPalette
153 \o Set by setPalette().
154 \row \o Qt::WA_SetFont
155 \o Set by setPalette().
156 \row \o Qt::WA_WindowPropagation
157 \o Enables propagation to window widgets.
160 Although QGraphicsWidget inherits from both QObject and QGraphicsItem,
161 you should use the functions provided by QGraphicsItem, \e not QObject, to
162 manage the relationships between parent and child items. These functions
163 control the stacking order of items as well as their ownership.
165 \note The QObject::parent() should always return 0 for QGraphicsWidgets,
166 but this policy is not strictly defined.
168 \sa QGraphicsProxyWidget, QGraphicsItem, {Widgets and Layouts}
172 Constructs a QGraphicsWidget instance. The optional \a parent argument is
173 passed to QGraphicsItem's constructor. The optional \a wFlags argument
174 specifies the widget's window flags (e.g., whether the widget should be a
175 window, a tool, a popup, etc).
177 QGraphicsWidget::QGraphicsWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
178 : QGraphicsObject(*new QGraphicsWidgetPrivate, 0, 0), QGraphicsLayoutItem(0, false)
180 Q_D(QGraphicsWidget);
181 d->init(parent, wFlags);
187 Constructs a new QGraphicsWidget, using \a dd as parent.
189 QGraphicsWidget::QGraphicsWidget(QGraphicsWidgetPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene, Qt::WindowFlags wFlags)
190 : QGraphicsObject(dd, 0, scene), QGraphicsLayoutItem(0, false)
192 Q_D(QGraphicsWidget);
193 d->init(parent, wFlags);
198 \class QGraphicsWidgetStyles
200 We use this thread-safe class to maintain a hash of styles for widgets
201 styles. Note that QApplication::style() itself isn't thread-safe, QStyle
202 isn't thread-safe, and we don't have a thread-safe factory for creating
203 the default style, nor cloning a style.
205 class QGraphicsWidgetStyles
208 QStyle *styleForWidget(const QGraphicsWidget *widget) const
210 QMutexLocker locker(&mutex);
211 return styles.value(widget, 0);
214 void setStyleForWidget(QGraphicsWidget *widget, QStyle *style)
216 QMutexLocker locker(&mutex);
218 styles[widget] = style;
220 styles.remove(widget);
224 QMap<const QGraphicsWidget *, QStyle *> styles;
225 mutable QMutex mutex;
227 Q_GLOBAL_STATIC(QGraphicsWidgetStyles, widgetStyles)
230 Destroys the QGraphicsWidget instance.
232 QGraphicsWidget::~QGraphicsWidget()
234 Q_D(QGraphicsWidget);
236 // Remove all actions from this widget
237 for (int i = 0; i < d->actions.size(); ++i) {
238 QActionPrivate *apriv = d->actions.at(i)->d_func();
239 apriv->graphicsWidgets.removeAll(this);
244 if (QGraphicsScene *scn = scene()) {
245 QGraphicsScenePrivate *sceneD = scn->d_func();
246 if (sceneD->tabFocusFirst == this)
247 sceneD->tabFocusFirst = (d->focusNext == this ? 0 : d->focusNext);
249 d->focusPrev->d_func()->focusNext = d->focusNext;
250 d->focusNext->d_func()->focusPrev = d->focusPrev;
252 // Play it really safe
258 //we check if we have a layout previously
260 QGraphicsLayout *temp = d->layout;
261 foreach (QGraphicsItem * item, childItems()) {
262 // In case of a custom layout which doesn't remove and delete items, we ensure that
263 // the parent layout item does not point to the deleted layout. This code is here to
264 // avoid regression from 4.4 to 4.5, because according to 4.5 docs it is not really needed.
265 if (item->isWidget()) {
266 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
267 if (widget->parentLayoutItem() == d->layout)
268 widget->setParentLayoutItem(0);
275 // Remove this graphics widget from widgetStyles
276 widgetStyles()->setStyleForWidget(this, 0);
280 \property QGraphicsWidget::size
281 \brief the size of the widget
283 Calling resize() resizes the widget to a \a size bounded by minimumSize()
284 and maximumSize(). This property only affects the widget's width and
285 height (e.g., its right and bottom edges); the widget's position and
286 top-left corner remains unaffected.
288 Resizing a widget triggers the widget to immediately receive a
289 \l{QEvent::GraphicsSceneResize}{GraphicsSceneResize} event with the
290 widget's old and new size. If the widget has a layout assigned when this
291 event arrives, the layout will be activated and it will automatically
292 update any child widgets's geometry.
294 This property does not affect any layout of the parent widget. If the
295 widget itself is managed by a parent layout; e.g., it has a parent widget
296 with a layout assigned, that layout will not activate.
298 By default, this property contains a size with zero width and height.
300 \sa setGeometry(), QGraphicsSceneResizeEvent, QGraphicsLayout
302 QSizeF QGraphicsWidget::size() const
304 return QGraphicsLayoutItem::geometry().size();
307 void QGraphicsWidget::resize(const QSizeF &size)
309 setGeometry(QRectF(pos(), size));
313 \fn void QGraphicsWidget::resize(qreal w, qreal h)
315 This convenience function is equivalent to calling resize(QSizeF(w, h)).
317 \sa setGeometry(), setTransform()
321 \property QGraphicsWidget::sizePolicy
322 \brief the size policy for the widget
323 \sa sizePolicy(), setSizePolicy(), QWidget::sizePolicy()
327 \fn QGraphicsWidget::geometryChanged()
329 This signal gets emitted whenever the geometry is changed in setGeometry().
333 \property QGraphicsWidget::geometry
334 \brief the geometry of the widget
336 Sets the item's geometry to \a rect. The item's position and size are
337 modified as a result of calling this function. The item is first moved,
340 A side effect of calling this function is that the widget will receive
341 a move event and a resize event. Also, if the widget has a layout
342 assigned, the layout will activate.
344 \sa geometry(), resize()
346 void QGraphicsWidget::setGeometry(const QRectF &rect)
348 QGraphicsWidgetPrivate *wd = QGraphicsWidget::d_func();
349 QGraphicsLayoutItemPrivate *d = QGraphicsLayoutItem::d_ptr.data();
351 QPointF oldPos = d->geom.topLeft();
353 setAttribute(Qt::WA_Resized);
355 newGeom.setSize(rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize))
356 .boundedTo(effectiveSizeHint(Qt::MaximumSize)));
358 if (newGeom == d->geom) {
359 goto relayoutChildrenAndReturn;
362 // setPos triggers ItemPositionChange, which can adjust position
363 wd->inSetGeometry = 1;
364 setPos(newGeom.topLeft());
365 wd->inSetGeometry = 0;
366 newGeom.moveTopLeft(pos());
368 if (newGeom == d->geom) {
369 goto relayoutChildrenAndReturn;
372 // Update and prepare to change the geometry (remove from index) if the size has changed.
374 if (rect.topLeft() == d->geom.topLeft()) {
375 prepareGeometryChange();
380 // Update the layout item geometry
382 bool moved = oldPos != pos();
385 QGraphicsSceneMoveEvent event;
386 event.setOldPos(oldPos);
387 event.setNewPos(pos());
388 QApplication::sendEvent(this, &event);
391 d->geom.moveTopLeft(pos());
392 emit geometryChanged();
393 goto relayoutChildrenAndReturn;
396 QSizeF oldSize = size();
397 QGraphicsLayoutItem::setGeometry(newGeom);
399 bool resized = newGeom.size() != oldSize;
401 QGraphicsSceneResizeEvent re;
402 re.setOldSize(oldSize);
403 re.setNewSize(newGeom.size());
404 if (oldSize.width() != newGeom.size().width())
406 if (oldSize.height() != newGeom.size().height())
407 emit heightChanged();
408 QGraphicsLayout *lay = wd->layout;
409 if (QGraphicsLayout::instantInvalidatePropagation()) {
410 if (!lay || lay->isActivated()) {
411 QApplication::sendEvent(this, &re);
414 QApplication::sendEvent(this, &re);
419 emit geometryChanged();
420 relayoutChildrenAndReturn:
421 if (QGraphicsLayout::instantInvalidatePropagation()) {
422 if (QGraphicsLayout *lay = wd->layout) {
423 if (!lay->isActivated()) {
424 QEvent layoutRequest(QEvent::LayoutRequest);
425 QApplication::sendEvent(this, &layoutRequest);
432 \fn QRectF QGraphicsWidget::rect() const
434 Returns the item's local rect as a QRectF. This function is equivalent
435 to QRectF(QPointF(), size()).
437 \sa setGeometry(), resize()
441 \fn void QGraphicsWidget::setGeometry(qreal x, qreal y, qreal w, qreal h)
443 This convenience function is equivalent to calling setGeometry(QRectF(
444 \a x, \a y, \a w, \a h)).
446 \sa geometry(), resize()
450 \property QGraphicsWidget::minimumSize
451 \brief the minimum size of the widget
453 \sa setMinimumSize(), minimumSize(), preferredSize, maximumSize
457 \property QGraphicsWidget::preferredSize
458 \brief the preferred size of the widget
460 \sa setPreferredSize(), preferredSize(), minimumSize, maximumSize
464 \property QGraphicsWidget::maximumSize
465 \brief the maximum size of the widget
467 \sa setMaximumSize(), maximumSize(), minimumSize, preferredSize
471 Sets the widget's contents margins to \a left, \a top, \a right and \a
474 Contents margins are used by the assigned layout to define the placement
475 of subwidgets and layouts. Margins are particularly useful for widgets
476 that constrain subwidgets to only a section of its own geometry. For
477 example, a group box with a layout will place subwidgets inside its frame,
480 Changing a widget's contents margins will always trigger an update(), and
481 any assigned layout will be activated automatically. The widget will then
482 receive a \l{QEvent::ContentsRectChange}{ContentsRectChange} event.
484 \sa getContentsMargins(), setGeometry()
486 void QGraphicsWidget::setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
488 Q_D(QGraphicsWidget);
490 if (!d->margins && left == 0 && top == 0 && right == 0 && bottom == 0)
493 if (left == d->margins[d->Left]
494 && top == d->margins[d->Top]
495 && right == d->margins[d->Right]
496 && bottom == d->margins[d->Bottom])
499 d->margins[d->Left] = left;
500 d->margins[d->Top] = top;
501 d->margins[d->Right] = right;
502 d->margins[d->Bottom] = bottom;
504 if (QGraphicsLayout *l = d->layout)
509 QEvent e(QEvent::ContentsRectChange);
510 QApplication::sendEvent(this, &e);
514 Gets the widget's contents margins. The margins are stored in \a left, \a
515 top, \a right and \a bottom, as pointers to qreals. Each argument can
516 be \e {omitted} by passing 0.
518 \sa setContentsMargins()
520 void QGraphicsWidget::getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
522 Q_D(const QGraphicsWidget);
523 if (left || top || right || bottom)
526 *left = d->margins[d->Left];
528 *top = d->margins[d->Top];
530 *right = d->margins[d->Right];
532 *bottom = d->margins[d->Bottom];
536 Sets the widget's window frame margins to \a left, \a top, \a right and
537 \a bottom. The default frame margins are provided by the style, and they
538 depend on the current window flags.
540 If you would like to draw your own window decoration, you can set your
541 own frame margins to override the default margins.
543 \sa unsetWindowFrameMargins(), getWindowFrameMargins(), windowFrameRect()
545 void QGraphicsWidget::setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom)
547 Q_D(QGraphicsWidget);
549 if (!d->windowFrameMargins && left == 0 && top == 0 && right == 0 && bottom == 0)
551 d->ensureWindowFrameMargins();
553 d->windowFrameMargins[d->Left] == left
554 && d->windowFrameMargins[d->Top] == top
555 && d->windowFrameMargins[d->Right] == right
556 && d->windowFrameMargins[d->Bottom] == bottom;
557 if (d->setWindowFrameMargins && unchanged)
560 prepareGeometryChange();
561 d->windowFrameMargins[d->Left] = left;
562 d->windowFrameMargins[d->Top] = top;
563 d->windowFrameMargins[d->Right] = right;
564 d->windowFrameMargins[d->Bottom] = bottom;
565 d->setWindowFrameMargins = true;
569 Gets the widget's window frame margins. The margins are stored in \a left,
570 \a top, \a right and \a bottom as pointers to qreals. Each argument can
571 be \e {omitted} by passing 0.
573 \sa setWindowFrameMargins(), windowFrameRect()
575 void QGraphicsWidget::getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
577 Q_D(const QGraphicsWidget);
578 if (left || top || right || bottom)
579 d->ensureWindowFrameMargins();
581 *left = d->windowFrameMargins[d->Left];
583 *top = d->windowFrameMargins[d->Top];
585 *right = d->windowFrameMargins[d->Right];
587 *bottom = d->windowFrameMargins[d->Bottom];
591 Resets the window frame margins to the default value, provided by the style.
593 \sa setWindowFrameMargins(), getWindowFrameMargins(), windowFrameRect()
595 void QGraphicsWidget::unsetWindowFrameMargins()
597 Q_D(QGraphicsWidget);
598 if ((d->windowFlags & Qt::Window) && (d->windowFlags & Qt::WindowType_Mask) != Qt::Popup &&
599 (d->windowFlags & Qt::WindowType_Mask) != Qt::ToolTip && !(d->windowFlags & Qt::FramelessWindowHint)) {
600 QStyleOptionTitleBar bar;
601 d->initStyleOptionTitleBar(&bar);
602 QStyle *style = this->style();
603 qreal margin = style->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth);
604 qreal titleBarHeight = d->titleBarHeight(bar);
605 setWindowFrameMargins(margin, titleBarHeight, margin, margin);
607 setWindowFrameMargins(0, 0, 0, 0);
609 d->setWindowFrameMargins = false;
613 Returns the widget's geometry in parent coordinates including any window
616 \sa windowFrameRect(), getWindowFrameMargins(), setWindowFrameMargins()
618 QRectF QGraphicsWidget::windowFrameGeometry() const
620 Q_D(const QGraphicsWidget);
621 return d->windowFrameMargins
622 ? geometry().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top],
623 d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom])
628 Returns the widget's local rect including any window frame.
630 \sa windowFrameGeometry(), getWindowFrameMargins(), setWindowFrameMargins()
632 QRectF QGraphicsWidget::windowFrameRect() const
634 Q_D(const QGraphicsWidget);
635 return d->windowFrameMargins
636 ? rect().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top],
637 d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom])
642 Populates a style option object for this widget based on its current
643 state, and stores the output in \a option. The default implementation
644 populates \a option with the following properties.
648 \o Style Option Property
651 \o state & QStyle::State_Enabled
652 \o Corresponds to QGraphicsItem::isEnabled().
654 \o state & QStyle::State_HasFocus
655 \o Corresponds to QGraphicsItem::hasFocus().
657 \o state & QStyle::State_MouseOver
658 \o Corresponds to QGraphicsItem::isUnderMouse().
661 \o Corresponds to QGraphicsWidget::layoutDirection().
664 \o Corresponds to QGraphicsWidget::rect().toRect().
667 \o Corresponds to QGraphicsWidget::palette().
670 \o Corresponds to QFontMetrics(QGraphicsWidget::font()).
673 Subclasses of QGraphicsWidget should call the base implementation, and
674 then test the type of \a option using qstyleoption_cast<>() or test
675 QStyleOption::Type before storing widget-specific options.
679 \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp 0
681 \sa QStyleOption::initFrom()
683 void QGraphicsWidget::initStyleOption(QStyleOption *option) const
687 option->state = QStyle::State_None;
689 option->state |= QStyle::State_Enabled;
691 option->state |= QStyle::State_HasFocus;
692 // if (window->testAttribute(Qt::WA_KeyboardFocusChange)) // ### Window
693 // option->state |= QStyle::State_KeyboardFocusChange;
695 option->state |= QStyle::State_MouseOver;
696 if (QGraphicsWidget *w = window()) {
697 if (w->isActiveWindow())
698 option->state |= QStyle::State_Active;
701 option->state |= QStyle::State_Window;
705 extern bool qt_mac_can_clickThrough(const QGraphicsWidget *w); //qwidget_mac.cpp
706 if (!(option->state & QStyle::State_Active) && !qt_mac_can_clickThrough(widget))
707 option->state &= ~QStyle::State_Enabled;
709 switch (QMacStyle::widgetSizePolicy(widget)) {
710 case QMacStyle::SizeSmall:
711 option->state |= QStyle::State_Small;
713 case QMacStyle::SizeMini:
714 option->state |= QStyle::State_Mini;
720 #ifdef QT_KEYPAD_NAVIGATION
721 if (widget->hasEditFocus())
722 state |= QStyle::State_HasEditFocus;
725 option->direction = layoutDirection();
726 option->rect = rect().toRect(); // ### truncation!
727 option->palette = palette();
729 option->palette.setCurrentColorGroup(QPalette::Disabled);
730 } else if (isActiveWindow()) {
731 option->palette.setCurrentColorGroup(QPalette::Active);
733 option->palette.setCurrentColorGroup(QPalette::Inactive);
735 option->fontMetrics = QFontMetrics(font());
741 QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
743 Q_D(const QGraphicsWidget);
746 QSizeF marginSize(0,0);
748 marginSize = QSizeF(d->margins[d->Left] + d->margins[d->Right],
749 d->margins[d->Top] + d->margins[d->Bottom]);
751 sh = d->layout->effectiveSizeHint(which, constraint - marginSize);
755 case Qt::MinimumSize:
758 case Qt::PreferredSize:
759 sh = QSizeF(50, 50); //rather arbitrary
761 case Qt::MaximumSize:
762 sh = QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
765 qWarning("QGraphicsWidget::sizeHint(): Don't know how to handle the value of 'which'");
773 \property QGraphicsWidget::layout
774 \brief The layout of the widget
776 Any existing layout manager is deleted before the new layout is assigned. If
777 \a layout is 0, the widget is left without a layout. Existing subwidgets'
778 geometries will remain unaffected.
780 QGraphicsWidget takes ownership of \a layout.
782 All widgets that are currently managed by \a layout or all of its
783 sublayouts, are automatically reparented to this item. The layout is then
784 invalidated, and the child widget geometries are adjusted according to
785 this item's geometry() and contentsMargins(). Children who are not
786 explicitly managed by \a layout remain unaffected by the layout after
787 it has been assigned to this widget.
789 If no layout is currently managing this widget, layout() will return 0.
794 \fn void QGraphicsWidget::layoutChanged()
795 This signal gets emitted whenever the layout of the item changes
800 Returns this widget's layout, or 0 if no layout is currently managing this
805 QGraphicsLayout *QGraphicsWidget::layout() const
807 Q_D(const QGraphicsWidget);
812 \fn void QGraphicsWidget::setLayout(QGraphicsLayout *layout)
814 Sets the layout for this widget to \a layout. Any existing layout manager
815 is deleted before the new layout is assigned. If \a layout is 0, the
816 widget is left without a layout. Existing subwidgets' geometries will
819 All widgets that are currently managed by \a layout or all of its
820 sublayouts, are automatically reparented to this item. The layout is then
821 invalidated, and the child widget geometries are adjusted according to
822 this item's geometry() and contentsMargins(). Children who are not
823 explicitly managed by \a layout remain unaffected by the layout after
824 it has been assigned to this widget.
826 QGraphicsWidget takes ownership of \a layout.
828 \sa layout(), QGraphicsLinearLayout::addItem(), QGraphicsLayout::invalidate()
830 void QGraphicsWidget::setLayout(QGraphicsLayout *l)
832 Q_D(QGraphicsWidget);
835 d->setLayout_helper(l);
839 // Prevent assigning a layout that is already assigned to another widget.
840 QGraphicsLayoutItem *oldParent = l->parentLayoutItem();
841 if (oldParent && oldParent != this) {
842 qWarning("QGraphicsWidget::setLayout: Attempting to set a layout on %s"
843 " \"%s\", when the layout already has a parent",
844 metaObject()->className(), qPrintable(objectName()));
848 // Install and activate the layout.
849 l->setParentLayoutItem(this);
850 l->d_func()->reparentChildItems(this);
852 emit layoutChanged();
856 Adjusts the size of the widget to its effective preferred size hint.
858 This function is called implicitly when the item is shown for the first
861 \sa effectiveSizeHint(), Qt::MinimumSize
863 void QGraphicsWidget::adjustSize()
865 QSizeF sz = effectiveSizeHint(Qt::PreferredSize);
866 // What if sz is not valid?!
872 \property QGraphicsWidget::layoutDirection
873 \brief the layout direction for this widget.
875 This property modifies this widget's and all of its descendants'
876 Qt::WA_RightToLeft attribute. It also sets this widget's
877 Qt::WA_SetLayoutDirection attribute.
879 The widget's layout direction determines the order in which the layout
880 manager horizontally arranges subwidgets of this widget. The default
881 value depends on the language and locale of the application, and is
882 typically in the same direction as words are read and written. With
883 Qt::LeftToRight, the layout starts placing subwidgets from the left
884 side of this widget towards the right. Qt::RightToLeft does the opposite -
885 the layout will place widgets starting from the right edge moving towards
888 Subwidgets inherit their layout direction from the parent. Top-level
889 widget items inherit their layout direction from
890 QGraphicsScene::layoutDirection. If you change a widget's layout direction
891 by calling setLayoutDirection(), the widget will send itself a
892 \l{QEvent::LayoutDirectionChange}{LayoutDirectionChange} event, and then
893 propagate the new layout direction to all its descendants.
895 \sa QWidget::layoutDirection, QApplication::layoutDirection
897 Qt::LayoutDirection QGraphicsWidget::layoutDirection() const
899 return testAttribute(Qt::WA_RightToLeft) ? Qt::RightToLeft : Qt::LeftToRight;
901 void QGraphicsWidget::setLayoutDirection(Qt::LayoutDirection direction)
903 Q_D(QGraphicsWidget);
904 setAttribute(Qt::WA_SetLayoutDirection, true);
905 d->setLayoutDirection_helper(direction);
907 void QGraphicsWidget::unsetLayoutDirection()
909 Q_D(QGraphicsWidget);
910 setAttribute(Qt::WA_SetLayoutDirection, false);
911 d->resolveLayoutDirection();
915 Returns a pointer to the widget's style. If this widget does not have any
916 explicitly assigned style, the scene's style is returned instead. In turn,
917 if the scene does not have any assigned style, this function returns
918 QApplication::style().
922 QStyle *QGraphicsWidget::style() const
924 if (QStyle *style = widgetStyles()->styleForWidget(this))
926 // ### This is not thread-safe. QApplication::style() is not thread-safe.
927 return scene() ? scene()->style() : QApplication::style();
931 Sets the widget's style to \a style. QGraphicsWidget does \e not take
932 ownership of \a style.
934 If no style is assigned, or \a style is 0, the widget will use
935 QGraphicsScene::style() (if this has been set). Otherwise the widget will
936 use QApplication::style().
938 This function sets the Qt::WA_SetStyle attribute if \a style is not 0;
939 otherwise it clears the attribute.
943 void QGraphicsWidget::setStyle(QStyle *style)
945 setAttribute(Qt::WA_SetStyle, style != 0);
946 widgetStyles()->setStyleForWidget(this, style);
948 // Deliver StyleChange to the widget itself (doesn't propagate).
949 QEvent event(QEvent::StyleChange);
950 QApplication::sendEvent(this, &event);
954 \property QGraphicsWidget::font
955 \brief the widgets' font
957 This property provides the widget's font.
959 QFont consists of font properties that have been explicitly defined and
960 properties implicitly inherited from the widget's parent. Hence, font()
961 can return a different font compared to the one set with setFont().
962 This scheme allows you to define single entries in a font without
963 affecting the font's inherited entries.
965 When a widget's font changes, it resolves its entries against its
966 parent widget. If the widget does not have a parent widget, it resolves
967 its entries against the scene. The widget then sends itself a
968 \l{QEvent::FontChange}{FontChange} event and notifies all its
969 descendants so that they can resolve their fonts as well.
971 By default, this property contains the application's default font.
973 \sa QApplication::font(), QGraphicsScene::font, QFont::resolve()
975 QFont QGraphicsWidget::font() const
977 Q_D(const QGraphicsWidget);
979 fnt.resolve(fnt.resolve() | d->inheritedFontResolveMask);
982 void QGraphicsWidget::setFont(const QFont &font)
984 Q_D(QGraphicsWidget);
985 setAttribute(Qt::WA_SetFont, font.resolve() != 0);
987 QFont naturalFont = d->naturalWidgetFont();
988 QFont resolvedFont = font.resolve(naturalFont);
989 d->setFont_helper(resolvedFont);
993 \property QGraphicsWidget::palette
994 \brief the widget's palette
996 This property provides the widget's palette. The palette provides colors
997 and brushes for color groups (e.g., QPalette::Button) and states (e.g.,
998 QPalette::Inactive), loosely defining the general look of the widget and
1001 QPalette consists of color groups that have been explicitly defined, and
1002 groups that are implicitly inherited from the widget's parent. Because of
1003 this, palette() can return a different palette than what has been set with
1004 setPalette(). This scheme allows you to define single entries in a palette
1005 without affecting the palette's inherited entries.
1007 When a widget's palette changes, it resolves its entries against its
1008 parent widget, or if it doesn't have a parent widget, it resolves against
1009 the scene. It then sends itself a \l{QEvent::PaletteChange}{PaletteChange}
1010 event, and notifies all its descendants so they can resolve their palettes
1013 By default, this property contains the application's default palette.
1015 \sa QApplication::palette(), QGraphicsScene::palette, QPalette::resolve()
1017 QPalette QGraphicsWidget::palette() const
1019 Q_D(const QGraphicsWidget);
1022 void QGraphicsWidget::setPalette(const QPalette &palette)
1024 Q_D(QGraphicsWidget);
1025 setAttribute(Qt::WA_SetPalette, palette.resolve() != 0);
1027 QPalette naturalPalette = d->naturalWidgetPalette();
1028 QPalette resolvedPalette = palette.resolve(naturalPalette);
1029 d->setPalette_helper(resolvedPalette);
1033 \property QGraphicsWidget::autoFillBackground
1034 \brief whether the widget background is filled automatically
1037 If enabled, this property will cause Qt to fill the background of the
1038 widget before invoking the paint() method. The color used is defined by the
1039 QPalette::Window color role from the widget's \l{QPalette}{palette}.
1041 In addition, Windows are always filled with QPalette::Window, unless the
1042 WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.
1044 By default, this property is false.
1046 \sa Qt::WA_OpaquePaintEvent, Qt::WA_NoSystemBackground,
1048 bool QGraphicsWidget::autoFillBackground() const
1050 Q_D(const QGraphicsWidget);
1051 return d->autoFillBackground;
1053 void QGraphicsWidget::setAutoFillBackground(bool enabled)
1055 Q_D(QGraphicsWidget);
1056 if (d->autoFillBackground != enabled) {
1057 d->autoFillBackground = enabled;
1063 If this widget is currently managed by a layout, this function notifies
1064 the layout that the widget's size hints have changed and the layout
1065 may need to resize and reposition the widget accordingly.
1067 Call this function if the widget's sizeHint() has changed.
1069 \sa QGraphicsLayout::invalidate()
1071 void QGraphicsWidget::updateGeometry()
1073 QGraphicsLayoutItem::updateGeometry();
1074 QGraphicsLayoutItem *parentItem = parentLayoutItem();
1076 if (parentItem && parentItem->isLayout()) {
1077 if (QGraphicsLayout::instantInvalidatePropagation()) {
1078 static_cast<QGraphicsLayout *>(parentItem)->invalidate();
1080 parentItem->updateGeometry();
1084 // This is for custom layouting
1085 QGraphicsWidget *parentWid = parentWidget(); //###
1086 if (parentWid->isVisible())
1087 QApplication::postEvent(parentWid, new QEvent(QEvent::LayoutRequest));
1090 * If this is the topmost widget, post a LayoutRequest event to the widget.
1091 * When the event is received, it will start flowing all the way down to the leaf
1092 * widgets in one go. This will make a relayout flicker-free.
1094 if (QGraphicsLayout::instantInvalidatePropagation())
1095 QApplication::postEvent(static_cast<QGraphicsWidget *>(this), new QEvent(QEvent::LayoutRequest));
1097 if (!QGraphicsLayout::instantInvalidatePropagation()) {
1098 bool wasResized = testAttribute(Qt::WA_Resized);
1099 resize(size()); // this will restrict the size
1100 setAttribute(Qt::WA_Resized, wasResized);
1108 QGraphicsWidget uses the base implementation of this function to catch and
1109 deliver events related to state changes in the item. Because of this, it is
1110 very important that subclasses call the base implementation.
1112 \a change specifies the type of change, and \a value is the new value.
1114 For example, QGraphicsWidget uses ItemVisibleChange to deliver
1115 \l{QEvent::Show} {Show} and \l{QEvent::Hide}{Hide} events,
1116 ItemPositionHasChanged to deliver \l{QEvent::Move}{Move} events,
1117 and ItemParentChange both to deliver \l{QEvent::ParentChange}
1118 {ParentChange} events, and for managing the focus chain.
1120 QGraphicsWidget enables the ItemSendsGeometryChanges flag by default in
1121 order to track position changes.
1123 \sa QGraphicsItem::itemChange()
1125 QVariant QGraphicsWidget::itemChange(GraphicsItemChange change, const QVariant &value)
1127 Q_D(QGraphicsWidget);
1129 case ItemEnabledHasChanged: {
1130 // Send EnabledChange after the enabled state has changed.
1131 QEvent event(QEvent::EnabledChange);
1132 QApplication::sendEvent(this, &event);
1135 case ItemVisibleChange:
1136 if (value.toBool()) {
1137 // Send Show event before the item has been shown.
1139 QApplication::sendEvent(this, &event);
1140 bool resized = testAttribute(Qt::WA_Resized);
1143 setAttribute(Qt::WA_Resized, false);
1147 case ItemVisibleHasChanged:
1148 if (!value.toBool()) {
1149 // Send Hide event after the item has been hidden.
1151 QApplication::sendEvent(this, &event);
1154 case ItemPositionHasChanged:
1155 d->setGeometryFromSetPos();
1157 case ItemParentChange: {
1158 // Deliver ParentAboutToChange.
1159 QEvent event(QEvent::ParentAboutToChange);
1160 QApplication::sendEvent(this, &event);
1163 case ItemParentHasChanged: {
1164 // Deliver ParentChange.
1165 QEvent event(QEvent::ParentChange);
1166 QApplication::sendEvent(this, &event);
1169 case ItemCursorHasChanged: {
1170 // Deliver CursorChange.
1171 QEvent event(QEvent::CursorChange);
1172 QApplication::sendEvent(this, &event);
1175 case ItemToolTipHasChanged: {
1176 // Deliver ToolTipChange.
1177 QEvent event(QEvent::ToolTipChange);
1178 QApplication::sendEvent(this, &event);
1184 return QGraphicsItem::itemChange(change, value);
1190 This virtual function is used to notify changes to any property (both
1191 dynamic properties, and registered with Q_PROPERTY) in the
1192 widget. Depending on the property itself, the notification can be
1193 delivered before or after the value has changed.
1195 \a propertyName is the name of the property (e.g., "size" or "font"), and
1196 \a value is the (proposed) new value of the property. The function returns
1197 the new value, which may be different from \a value if the notification
1198 supports adjusting the property value. The base implementation simply
1199 returns \a value for any \a propertyName.
1201 QGraphicsWidget delivers notifications for the following properties:
1203 \table \o propertyName \o Property
1204 \row \o layoutDirection \o QGraphicsWidget::layoutDirection
1205 \row \o size \o QGraphicsWidget::size
1206 \row \o font \o QGraphicsWidget::font
1207 \row \o palette \o QGraphicsWidget::palette
1212 QVariant QGraphicsWidget::propertyChange(const QString &propertyName, const QVariant &value)
1214 Q_UNUSED(propertyName);
1219 QGraphicsWidget's implementation of sceneEvent() simply passes \a event to
1220 QGraphicsWidget::event(). You can handle all events for your widget in
1221 event() or in any of the convenience functions; you should not have to
1222 reimplement this function in a subclass of QGraphicsWidget.
1224 \sa QGraphicsItem::sceneEvent()
1226 bool QGraphicsWidget::sceneEvent(QEvent *event)
1228 return QGraphicsItem::sceneEvent(event);
1232 This event handler, for \a event, receives events for the window frame if
1233 this widget is a window. Its base implementation provides support for
1234 default window frame interaction such as moving, resizing, etc.
1236 You can reimplement this handler in a subclass of QGraphicsWidget to
1237 provide your own custom window frame interaction support.
1239 Returns true if \a event has been recognized and processed; otherwise,
1244 bool QGraphicsWidget::windowFrameEvent(QEvent *event)
1246 Q_D(QGraphicsWidget);
1247 switch (event->type()) {
1248 case QEvent::GraphicsSceneMousePress:
1249 d->windowFrameMousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
1251 case QEvent::GraphicsSceneMouseMove:
1252 d->ensureWindowData();
1253 if (d->windowData->grabbedSection != Qt::NoSection) {
1254 d->windowFrameMouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
1258 case QEvent::GraphicsSceneMouseRelease:
1259 d->windowFrameMouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
1261 case QEvent::GraphicsSceneHoverMove:
1262 d->windowFrameHoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
1264 case QEvent::GraphicsSceneHoverLeave:
1265 d->windowFrameHoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
1270 return event->isAccepted();
1276 Returns the window frame section at position \a pos, or
1277 Qt::NoSection if there is no window frame section at this
1280 This function is used in QGraphicsWidget's base implementation for window
1283 You can reimplement this function if you want to customize how a window
1284 can be interactively moved or resized. For instance, if you only want to
1285 allow a window to be resized by the bottom right corner, you can
1286 reimplement this function to return Qt::NoSection for all sections except
1287 Qt::BottomRightSection.
1289 \sa windowFrameEvent(), paintWindowFrame(), windowFrameGeometry()
1291 Qt::WindowFrameSection QGraphicsWidget::windowFrameSectionAt(const QPointF &pos) const
1293 Q_D(const QGraphicsWidget);
1295 const QRectF r = windowFrameRect();
1296 if (!r.contains(pos))
1297 return Qt::NoSection;
1299 const qreal left = r.left();
1300 const qreal top = r.top();
1301 const qreal right = r.right();
1302 const qreal bottom = r.bottom();
1303 const qreal x = pos.x();
1304 const qreal y = pos.y();
1306 const qreal cornerMargin = 20;
1307 //### Not sure of this one, it should be the same value for all edges.
1308 const qreal windowFrameWidth = d->windowFrameMargins
1309 ? d->windowFrameMargins[d->Left] : 0;
1311 Qt::WindowFrameSection s = Qt::NoSection;
1312 if (x <= left + cornerMargin) {
1313 if (y <= top + windowFrameWidth || (x <= left + windowFrameWidth && y <= top + cornerMargin)) {
1314 s = Qt::TopLeftSection;
1315 } else if (y >= bottom - windowFrameWidth || (x <= left + windowFrameWidth && y >= bottom - windowFrameWidth)) {
1316 s = Qt::BottomLeftSection;
1317 } else if (x <= left + windowFrameWidth) {
1318 s = Qt::LeftSection;
1320 } else if (x >= right - cornerMargin) {
1321 if (y <= top + windowFrameWidth || (x >= right - windowFrameWidth && y <= top + cornerMargin)) {
1322 s = Qt::TopRightSection;
1323 } else if (y >= bottom - windowFrameWidth || (x >= right - windowFrameWidth && y >= bottom - windowFrameWidth)) {
1324 s = Qt::BottomRightSection;
1325 } else if (x >= right - windowFrameWidth) {
1326 s = Qt::RightSection;
1328 } else if (y <= top + windowFrameWidth) {
1330 } else if (y >= bottom - windowFrameWidth) {
1331 s = Qt::BottomSection;
1333 if (s == Qt::NoSection) {
1335 r1.setHeight(d->windowFrameMargins
1336 ? d->windowFrameMargins[d->Top] : 0);
1337 if (r1.contains(pos))
1338 s = Qt::TitleBarArea;
1346 Handles the \a event. QGraphicsWidget handles the following
1349 \table \o Event \o Usage
1351 \o Delivered to the widget some time after it has been
1353 \row \o GraphicsSceneMove
1354 \o Delivered to the widget after its local position has
1356 \row \o GraphicsSceneResize
1357 \o Delivered to the widget after its size has changed.
1359 \o Delivered to the widget before it has been shown.
1361 \o Delivered to the widget after it has been hidden.
1362 \row \o PaletteChange
1363 \o Delivered to the widget after its palette has changed.
1365 \o Delivered to the widget after its font has changed.
1366 \row \o EnabledChange
1367 \o Delivered to the widget after its enabled state has
1370 \o Delivered to the widget after its style has changed.
1371 \row \o LayoutDirectionChange
1372 \o Delivered to the widget after its layout direction has
1374 \row \o ContentsRectChange
1375 \o Delivered to the widget after its contents margins/
1376 contents rect has changed.
1379 bool QGraphicsWidget::event(QEvent *event)
1381 Q_D(QGraphicsWidget);
1382 // Forward the event to the layout first.
1384 d->layout->widgetEvent(event);
1386 // Handle the event itself.
1387 switch (event->type()) {
1388 case QEvent::GraphicsSceneMove:
1389 moveEvent(static_cast<QGraphicsSceneMoveEvent *>(event));
1391 case QEvent::GraphicsSceneResize:
1392 resizeEvent(static_cast<QGraphicsSceneResizeEvent *>(event));
1395 showEvent(static_cast<QShowEvent *>(event));
1398 hideEvent(static_cast<QHideEvent *>(event));
1400 case QEvent::Polish:
1403 if (!d->font.isCopyOf(QApplication::font()))
1404 d->updateFont(d->font);
1406 case QEvent::WindowActivate:
1407 case QEvent::WindowDeactivate:
1410 // Taken from QWidget::event
1411 case QEvent::ActivationChange:
1412 case QEvent::EnabledChange:
1413 case QEvent::FontChange:
1414 case QEvent::StyleChange:
1415 case QEvent::PaletteChange:
1416 case QEvent::ParentChange:
1417 case QEvent::ContentsRectChange:
1418 case QEvent::LayoutDirectionChange:
1422 closeEvent((QCloseEvent *)event);
1424 case QEvent::GrabMouse:
1425 grabMouseEvent(event);
1427 case QEvent::UngrabMouse:
1428 ungrabMouseEvent(event);
1430 case QEvent::GrabKeyboard:
1431 grabKeyboardEvent(event);
1433 case QEvent::UngrabKeyboard:
1434 ungrabKeyboardEvent(event);
1436 case QEvent::GraphicsSceneMousePress:
1437 if (d->hasDecoration() && windowFrameEvent(event))
1439 case QEvent::GraphicsSceneMouseMove:
1440 case QEvent::GraphicsSceneMouseRelease:
1441 case QEvent::GraphicsSceneMouseDoubleClick:
1442 d->ensureWindowData();
1443 if (d->hasDecoration() && d->windowData->grabbedSection != Qt::NoSection)
1444 return windowFrameEvent(event);
1446 case QEvent::GraphicsSceneHoverEnter:
1447 case QEvent::GraphicsSceneHoverMove:
1448 case QEvent::GraphicsSceneHoverLeave:
1449 if (d->hasDecoration()) {
1450 windowFrameEvent(event);
1451 // Filter out hover events if they were sent to us only because of the
1452 // decoration (special case in QGraphicsScenePrivate::dispatchHoverEvent).
1453 if (!acceptsHoverEvents())
1460 return QObject::event(event);
1464 This event handler can be reimplemented to handle state changes.
1466 The state being changed in this event can be retrieved through \a event.
1468 Change events include: QEvent::ActivationChange, QEvent::EnabledChange,
1469 QEvent::FontChange, QEvent::StyleChange, QEvent::PaletteChange,
1470 QEvent::ParentChange, QEvent::LayoutDirectionChange, and
1471 QEvent::ContentsRectChange.
1473 void QGraphicsWidget::changeEvent(QEvent *event)
1475 Q_D(QGraphicsWidget);
1476 switch (event->type()) {
1477 case QEvent::StyleChange:
1478 // ### Don't unset if the margins are explicitly set.
1479 unsetWindowFrameMargins();
1481 d->layout->invalidate();
1482 case QEvent::FontChange:
1486 case QEvent::PaletteChange:
1489 case QEvent::ParentChange:
1490 d->resolveFont(d->inheritedFontResolveMask);
1491 d->resolvePalette(d->inheritedPaletteResolveMask);
1499 This event handler, for \a event, can be reimplemented in a subclass to
1500 receive widget close events. The default implementation accepts the
1503 \sa close(), QCloseEvent
1505 void QGraphicsWidget::closeEvent(QCloseEvent *event)
1513 void QGraphicsWidget::focusInEvent(QFocusEvent *event)
1516 if (focusPolicy() != Qt::NoFocus)
1521 Finds a new widget to give the keyboard focus to, as appropriate for Tab
1522 and Shift+Tab, and returns true if it can find a new widget; returns false
1523 otherwise. If \a next is true, this function searches forward; if \a next
1524 is false, it searches backward.
1526 Sometimes, you will want to reimplement this function to provide special
1527 focus handling for your widget and its subwidgets. For example, a web
1528 browser might reimplement it to move its current active link forward or
1529 backward, and call the base implementation only when it reaches the last
1530 or first link on the page.
1532 Child widgets call focusNextPrevChild() on their parent widgets, but only
1533 the window that contains the child widgets decides where to redirect
1534 focus. By reimplementing this function for an object, you gain control of
1535 focus traversal for all child widgets.
1539 bool QGraphicsWidget::focusNextPrevChild(bool next)
1541 Q_D(QGraphicsWidget);
1542 // Let the parent's focusNextPrevChild implementation decide what to do.
1543 QGraphicsWidget *parent = 0;
1544 if (!isWindow() && (parent = parentWidget()))
1545 return parent->focusNextPrevChild(next);
1548 if (d->scene->focusNextPrevChild(next))
1551 setFocus(next ? Qt::TabFocusReason : Qt::BacktabFocusReason);
1561 void QGraphicsWidget::focusOutEvent(QFocusEvent *event)
1564 if (focusPolicy() != Qt::NoFocus)
1569 This event handler, for \l{QEvent::Hide}{Hide} events, is delivered after
1570 the widget has been hidden, for example, setVisible(false) has been called
1571 for the widget or one of its ancestors when the widget was previously
1574 You can reimplement this event handler to detect when your widget is
1575 hidden. Calling QEvent::accept() or QEvent::ignore() on \a event has no
1578 \sa showEvent(), QWidget::hideEvent(), ItemVisibleChange
1580 void QGraphicsWidget::hideEvent(QHideEvent *event)
1582 ///### focusNextPrevChild(true), don't lose focus when the focus widget
1588 This event handler, for \l{QEvent::GraphicsSceneMove}{GraphicsSceneMove}
1589 events, is delivered after the widget has moved (e.g., its local position
1592 This event is only delivered when the item is moved locally. Calling
1593 setTransform() or moving any of the item's ancestors does not affect the
1594 item's local position.
1596 You can reimplement this event handler to detect when your widget has
1597 moved. Calling QEvent::accept() or QEvent::ignore() on \a event has no
1600 \sa ItemPositionChange, ItemPositionHasChanged
1602 void QGraphicsWidget::moveEvent(QGraphicsSceneMoveEvent *event)
1604 // ### Last position is always == current position
1609 This event is delivered to the item by the scene at some point after it
1610 has been constructed, but before it is shown or otherwise accessed through
1611 the scene. You can use this event handler to do last-minute initializations
1612 of the widget which require the item to be fully constructed.
1614 The base implementation does nothing.
1616 void QGraphicsWidget::polishEvent()
1621 This event handler, for
1622 \l{QEvent::GraphicsSceneResize}{GraphicsSceneResize} events, is
1623 delivered after the widget has been resized (i.e., its local size has
1624 changed). \a event contains both the old and the new size.
1626 This event is only delivered when the widget is resized locally; calling
1627 setTransform() on the widget or any of its ancestors or view, does not
1628 affect the widget's local size.
1630 You can reimplement this event handler to detect when your widget has been
1631 resized. Calling QEvent::accept() or QEvent::ignore() on \a event has no
1634 \sa geometry(), setGeometry()
1636 void QGraphicsWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
1642 This event handler, for \l{QEvent::Show}{Show} events, is delivered before
1643 the widget has been shown, for example, setVisible(true) has been called
1644 for the widget or one of its ancestors when the widget was previously
1647 You can reimplement this event handler to detect when your widget is
1648 shown. Calling QEvent::accept() or QEvent::ignore() on \a event has no
1651 \sa hideEvent(), QWidget::showEvent(), ItemVisibleChange
1653 void QGraphicsWidget::showEvent(QShowEvent *event)
1661 void QGraphicsWidget::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
1669 void QGraphicsWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
1675 This event handler, for \a event, can be reimplemented in a subclass to
1676 receive notifications for Qt::GrabMouse events.
1678 \sa grabMouse(), grabKeyboard()
1680 void QGraphicsWidget::grabMouseEvent(QEvent *event)
1686 This event handler, for \a event, can be reimplemented in a subclass to
1687 receive notifications for Qt::UngrabMouse events.
1689 \sa ungrabMouse(), ungrabKeyboard()
1691 void QGraphicsWidget::ungrabMouseEvent(QEvent *event)
1697 This event handler, for \a event, can be reimplemented in a subclass to
1698 receive notifications for Qt::GrabKeyboard events.
1700 \sa grabKeyboard(), grabMouse()
1702 void QGraphicsWidget::grabKeyboardEvent(QEvent *event)
1708 This event handler, for \a event, can be reimplemented in a subclass to
1709 receive notifications for Qt::UngrabKeyboard events.
1711 \sa ungrabKeyboard(), ungrabMouse()
1713 void QGraphicsWidget::ungrabKeyboardEvent(QEvent *event)
1719 Returns the widgets window type.
1721 \sa windowFlags(), isWindow(), isPanel()
1723 Qt::WindowType QGraphicsWidget::windowType() const
1725 return Qt::WindowType(int(windowFlags()) & Qt::WindowType_Mask);
1729 \property QGraphicsWidget::windowFlags
1730 \brief the widget's window flags
1732 Window flags are a combination of a window type (e.g., Qt::Dialog) and
1733 several flags giving hints on the behavior of the window. The behavior
1734 is platform-dependent.
1736 By default, this property contains no window flags.
1738 Windows are panels. If you set the Qt::Window flag, the ItemIsPanel flag
1739 will be set automatically. If you clear the Qt::Window flag, the
1740 ItemIsPanel flag is also cleared. Note that the ItemIsPanel flag can be
1741 set independently of Qt::Window.
1743 \sa isWindow(), isPanel()
1745 Qt::WindowFlags QGraphicsWidget::windowFlags() const
1747 Q_D(const QGraphicsWidget);
1748 return d->windowFlags;
1750 void QGraphicsWidget::setWindowFlags(Qt::WindowFlags wFlags)
1752 Q_D(QGraphicsWidget);
1753 if (d->windowFlags == wFlags)
1755 bool wasPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup;
1757 d->adjustWindowFlags(&wFlags);
1758 d->windowFlags = wFlags;
1759 if (!d->setWindowFrameMargins)
1760 unsetWindowFrameMargins();
1762 setFlag(ItemIsPanel, d->windowFlags & Qt::Window);
1764 bool isPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup;
1765 if (d->scene && isVisible() && wasPopup != isPopup) {
1766 // Popup state changed; update implicit mouse grab.
1768 d->scene->d_func()->removePopup(this);
1770 d->scene->d_func()->addPopup(this);
1773 if (d->scene && d->scene->d_func()->allItemsIgnoreHoverEvents && d->hasDecoration()) {
1774 d->scene->d_func()->allItemsIgnoreHoverEvents = false;
1775 d->scene->d_func()->enableMouseTrackingOnViews();
1780 Returns true if this widget's window is in the active window, or if the
1781 widget does not have a window but is in an active scene (i.e., a scene
1782 that currently has focus).
1784 The active window is the window that either contains a child widget that
1785 currently has input focus, or that itself has input focus.
1787 \sa QGraphicsScene::activeWindow(), QGraphicsScene::setActiveWindow(), isActive()
1789 bool QGraphicsWidget::isActiveWindow() const
1795 \property QGraphicsWidget::windowTitle
1796 \brief This property holds the window title (caption).
1798 This property is only used for windows.
1800 By default, if no title has been set, this property contains an
1803 void QGraphicsWidget::setWindowTitle(const QString &title)
1805 Q_D(QGraphicsWidget);
1806 d->ensureWindowData();
1807 d->windowData->windowTitle = title;
1809 QString QGraphicsWidget::windowTitle() const
1811 Q_D(const QGraphicsWidget);
1812 return d->windowData ? d->windowData->windowTitle : QString();
1816 \property QGraphicsWidget::focusPolicy
1817 \brief the way the widget accepts keyboard focus
1819 The focus policy is Qt::TabFocus if the widget accepts keyboard focus by
1820 tabbing, Qt::ClickFocus if the widget accepts focus by clicking,
1821 Qt::StrongFocus if it accepts both, and Qt::NoFocus (the default) if it
1822 does not accept focus at all.
1824 You must enable keyboard focus for a widget if it processes keyboard
1825 events. This is normally done from the widget's constructor. For instance,
1826 the QLineEdit constructor calls setFocusPolicy(Qt::StrongFocus).
1828 If you enable a focus policy (i.e., not Qt::NoFocus), QGraphicsWidget will
1829 automatically enable the ItemIsFocusable flag. Setting Qt::NoFocus on a
1830 widget will clear the ItemIsFocusable flag. If the widget currently has
1831 keyboard focus, the widget will automatically lose focus.
1833 \sa focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), enabled
1835 Qt::FocusPolicy QGraphicsWidget::focusPolicy() const
1837 Q_D(const QGraphicsWidget);
1838 return d->focusPolicy;
1840 void QGraphicsWidget::setFocusPolicy(Qt::FocusPolicy policy)
1842 Q_D(QGraphicsWidget);
1843 if (d->focusPolicy == policy)
1845 d->focusPolicy = policy;
1846 if (hasFocus() && policy == Qt::NoFocus)
1848 setFlag(ItemIsFocusable, policy != Qt::NoFocus);
1852 If this widget, a child or descendant of this widget currently has input
1853 focus, this function will return a pointer to that widget. If
1854 no descendant widget has input focus, 0 is returned.
1856 \sa QGraphicsItem::focusItem(), QWidget::focusWidget()
1858 QGraphicsWidget *QGraphicsWidget::focusWidget() const
1860 Q_D(const QGraphicsWidget);
1861 if (d->subFocusItem && d->subFocusItem->d_ptr->isWidget)
1862 return static_cast<QGraphicsWidget *>(d->subFocusItem);
1866 #ifndef QT_NO_SHORTCUT
1870 Adds a shortcut to Qt's shortcut system that watches for the given key \a
1871 sequence in the given \a context. If the \a context is
1872 Qt::ApplicationShortcut, the shortcut applies to the application as a
1873 whole. Otherwise, it is either local to this widget, Qt::WidgetShortcut,
1874 or to the window itself, Qt::WindowShortcut. For widgets that are not part
1875 of a window (i.e., top-level widgets and their children),
1876 Qt::WindowShortcut shortcuts apply to the scene.
1878 If the same key \a sequence has been grabbed by several widgets,
1879 when the key \a sequence occurs a QEvent::Shortcut event is sent
1880 to all the widgets to which it applies in a non-deterministic
1881 order, but with the ``ambiguous'' flag set to true.
1883 \warning You should not normally need to use this function;
1884 instead create \l{QAction}s with the shortcut key sequences you
1885 require (if you also want equivalent menu options and toolbar
1886 buttons), or create \l{QShortcut}s if you just need key sequences.
1887 Both QAction and QShortcut handle all the event filtering for you,
1888 and provide signals which are triggered when the user triggers the
1889 key sequence, so are much easier to use than this low-level
1892 \sa releaseShortcut() setShortcutEnabled() QWidget::grabShortcut()
1894 int QGraphicsWidget::grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context)
1897 if (sequence.isEmpty())
1899 // ### setAttribute(Qt::WA_GrabbedShortcut);
1900 return qApp->d_func()->shortcutMap.addShortcut(this, sequence, context);
1906 Removes the shortcut with the given \a id from Qt's shortcut
1907 system. The widget will no longer receive QEvent::Shortcut events
1908 for the shortcut's key sequence (unless it has other shortcuts
1909 with the same key sequence).
1911 \warning You should not normally need to use this function since
1912 Qt's shortcut system removes shortcuts automatically when their
1913 parent widget is destroyed. It is best to use QAction or
1914 QShortcut to handle shortcuts, since they are easier to use than
1915 this low-level function. Note also that this is an expensive
1918 \sa grabShortcut() setShortcutEnabled() , QWidget::releaseShortcut()
1920 void QGraphicsWidget::releaseShortcut(int id)
1924 qApp->d_func()->shortcutMap.removeShortcut(id, this, 0);
1930 If \a enabled is true, the shortcut with the given \a id is
1931 enabled; otherwise the shortcut is disabled.
1933 \warning You should not normally need to use this function since
1934 Qt's shortcut system enables/disables shortcuts automatically as
1935 widgets become hidden/visible and gain or lose focus. It is best
1936 to use QAction or QShortcut to handle shortcuts, since they are
1937 easier to use than this low-level function.
1939 \sa grabShortcut() releaseShortcut(), QWidget::setShortcutEnabled()
1941 void QGraphicsWidget::setShortcutEnabled(int id, bool enabled)
1945 qApp->d_func()->shortcutMap.setShortcutEnabled(enabled, id, this, 0);
1951 If \a enabled is true, auto repeat of the shortcut with the
1952 given \a id is enabled; otherwise it is disabled.
1954 \sa grabShortcut() releaseShortcut() QWidget::setShortcutAutoRepeat()
1956 void QGraphicsWidget::setShortcutAutoRepeat(int id, bool enabled)
1960 qApp->d_func()->shortcutMap.setShortcutAutoRepeat(enabled, id, this, 0);
1964 #ifndef QT_NO_ACTION
1968 Appends the action \a action to this widget's list of actions.
1970 All QGraphicsWidgets have a list of \l{QAction}s, however they can be
1971 represented graphically in many different ways. The default use of the
1972 QAction list (as returned by actions()) is to create a context QMenu.
1974 A QGraphicsWidget should only have one of each action and adding an action
1975 it already has will not cause the same action to be in the widget twice.
1977 \sa removeAction(), insertAction(), actions(), QWidget::addAction()
1979 void QGraphicsWidget::addAction(QAction *action)
1981 insertAction(0, action);
1987 Appends the actions \a actions to this widget's list of actions.
1989 \sa removeAction(), QMenu, addAction(), QWidget::addActions()
1991 void QGraphicsWidget::addActions(QList<QAction *> actions)
1993 for (int i = 0; i < actions.count(); ++i)
1994 insertAction(0, actions.at(i));
2000 Inserts the action \a action to this widget's list of actions,
2001 before the action \a before. It appends the action if \a before is 0 or
2002 \a before is not a valid action for this widget.
2004 A QGraphicsWidget should only have one of each action.
2006 \sa removeAction(), addAction(), QMenu, actions(),
2007 QWidget::insertActions()
2009 void QGraphicsWidget::insertAction(QAction *before, QAction *action)
2012 qWarning("QWidget::insertAction: Attempt to insert null action");
2016 Q_D(QGraphicsWidget);
2017 int index = d->actions.indexOf(action);
2019 d->actions.removeAt(index);
2021 int pos = d->actions.indexOf(before);
2024 pos = d->actions.size();
2026 d->actions.insert(pos, action);
2029 QActionPrivate *apriv = action->d_func();
2030 apriv->graphicsWidgets.append(this);
2033 QActionEvent e(QEvent::ActionAdded, action, before);
2034 QApplication::sendEvent(this, &e);
2040 Inserts the actions \a actions to this widget's list of actions,
2041 before the action \a before. It appends the action if \a before is 0 or
2042 \a before is not a valid action for this widget.
2044 A QGraphicsWidget can have at most one of each action.
2046 \sa removeAction(), QMenu, insertAction(), QWidget::insertActions()
2048 void QGraphicsWidget::insertActions(QAction *before, QList<QAction *> actions)
2050 for (int i = 0; i < actions.count(); ++i)
2051 insertAction(before, actions.at(i));
2057 Removes the action \a action from this widget's list of actions.
2059 \sa insertAction(), actions(), insertAction(), QWidget::removeAction()
2061 void QGraphicsWidget::removeAction(QAction *action)
2066 Q_D(QGraphicsWidget);
2068 QActionPrivate *apriv = action->d_func();
2069 apriv->graphicsWidgets.removeAll(this);
2071 if (d->actions.removeAll(action)) {
2072 QActionEvent e(QEvent::ActionRemoved, action);
2073 QApplication::sendEvent(this, &e);
2080 Returns the (possibly empty) list of this widget's actions.
2082 \sa insertAction(), removeAction(), QWidget::actions(),
2083 QAction::associatedWidgets(), QAction::associatedGraphicsWidgets()
2085 QList<QAction *> QGraphicsWidget::actions() const
2087 Q_D(const QGraphicsWidget);
2093 Moves the \a second widget around the ring of focus widgets so that
2094 keyboard focus moves from the \a first widget to the \a second widget when
2095 the Tab key is pressed.
2097 Note that since the tab order of the \a second widget is changed, you
2098 should order a chain like this:
2100 \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp 1
2104 \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp 2
2106 If \a first is 0, this indicates that \a second should be the first widget
2107 to receive input focus should the scene gain Tab focus (i.e., the user
2108 hits Tab so that focus passes into the scene). If \a second is 0, this
2109 indicates that \a first should be the first widget to gain focus if the
2110 scene gained BackTab focus.
2112 By default, tab order is defined implicitly using widget creation order.
2114 \sa focusPolicy, {Keyboard Focus}
2116 void QGraphicsWidget::setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second)
2118 if (!first && !second) {
2119 qWarning("QGraphicsWidget::setTabOrder(0, 0) is undefined");
2122 if ((first && second) && first->scene() != second->scene()) {
2123 qWarning("QGraphicsWidget::setTabOrder: scenes %p and %p are different",
2124 first->scene(), second->scene());
2127 QGraphicsScene *scene = first ? first->scene() : second->scene();
2128 if (!scene && (!first || !second)) {
2129 qWarning("QGraphicsWidget::setTabOrder: assigning tab order from/to the"
2130 " scene requires the item to be in a scene.");
2134 // If either first or second are 0, the scene's tabFocusFirst is updated
2135 // to point to the first item in the scene's focus chain. Then first or
2136 // second are set to point to tabFocusFirst.
2137 QGraphicsScenePrivate *sceneD = scene->d_func();
2139 sceneD->tabFocusFirst = second;
2143 sceneD->tabFocusFirst = first->d_func()->focusNext;
2147 // Both first and second are != 0.
2148 QGraphicsWidget *firstFocusNext = first->d_func()->focusNext;
2149 if (firstFocusNext == second) {
2154 // Update the focus chain.
2155 QGraphicsWidget *secondFocusPrev = second->d_func()->focusPrev;
2156 QGraphicsWidget *secondFocusNext = second->d_func()->focusNext;
2157 firstFocusNext->d_func()->focusPrev = second;
2158 first->d_func()->focusNext = second;
2159 second->d_func()->focusNext = firstFocusNext;
2160 second->d_func()->focusPrev = first;
2161 secondFocusPrev->d_func()->focusNext = secondFocusNext;
2162 secondFocusNext->d_func()->focusPrev = secondFocusPrev;
2164 Q_ASSERT(first->d_func()->focusNext->d_func()->focusPrev == first);
2165 Q_ASSERT(first->d_func()->focusPrev->d_func()->focusNext == first);
2167 Q_ASSERT(second->d_func()->focusNext->d_func()->focusPrev == second);
2168 Q_ASSERT(second->d_func()->focusPrev->d_func()->focusNext == second);
2173 If \a on is true, this function enables \a attribute; otherwise
2174 \a attribute is disabled.
2176 See the class documentation for QGraphicsWidget for a complete list of
2177 which attributes are supported, and what they are for.
2179 \sa testAttribute(), QWidget::setAttribute()
2181 void QGraphicsWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
2183 Q_D(QGraphicsWidget);
2184 // ### most flags require some immediate action
2185 // ### we might want to qWarn use of unsupported attributes
2186 // ### we might want to not use Qt::WidgetAttribute, but roll our own instead
2187 d->setAttribute(attribute, on);
2191 Returns true if \a attribute is enabled for this widget; otherwise,
2196 bool QGraphicsWidget::testAttribute(Qt::WidgetAttribute attribute) const
2198 Q_D(const QGraphicsWidget);
2199 return d->testAttribute(attribute);
2205 int QGraphicsWidget::type() const
2213 void QGraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
2221 This virtual function is called by QGraphicsScene to draw the window frame
2222 for windows using \a painter, \a option, and \a widget, in local
2223 coordinates. The base implementation uses the current style to render the
2224 frame and title bar.
2226 You can reimplement this function in a subclass of QGraphicsWidget to
2227 provide custom rendering of the widget's window frame.
2229 \sa QGraphicsItem::paint()
2231 void QGraphicsWidget::paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
2234 const bool fillBackground = !testAttribute(Qt::WA_OpaquePaintEvent)
2235 && !testAttribute(Qt::WA_NoSystemBackground);
2236 QGraphicsProxyWidget *proxy = qobject_cast<QGraphicsProxyWidget *>(this);
2237 const bool embeddedWidgetFillsOwnBackground = proxy && proxy->widget();
2239 if (rect().contains(option->exposedRect)) {
2240 if (fillBackground && !embeddedWidgetFillsOwnBackground)
2241 painter->fillRect(option->exposedRect, palette().window());
2245 Q_D(QGraphicsWidget);
2247 QRect windowFrameRect = QRect(QPoint(), windowFrameGeometry().size().toSize());
2248 QStyleOptionTitleBar bar;
2249 bar.QStyleOption::operator=(*option);
2250 d->initStyleOptionTitleBar(&bar); // this clear flags in bar.state
2251 d->ensureWindowData();
2252 if (d->windowData->buttonMouseOver)
2253 bar.state |= QStyle::State_MouseOver;
2255 bar.state &= ~QStyle::State_MouseOver;
2256 if (d->windowData->buttonSunken)
2257 bar.state |= QStyle::State_Sunken;
2259 bar.state &= ~QStyle::State_Sunken;
2261 bar.rect = windowFrameRect;
2263 // translate painter to make the style happy
2264 const QPointF styleOrigin = this->windowFrameRect().topLeft();
2265 painter->translate(styleOrigin);
2268 const QSize pixmapSize = windowFrameRect.size();
2269 if (pixmapSize.width() <= 0 || pixmapSize.height() <= 0)
2271 QPainter *realPainter = painter;
2272 QPixmap pm(pixmapSize);
2273 painter = new QPainter(&pm);
2277 QStyleHintReturnMask mask;
2278 bool setMask = style()->styleHint(QStyle::SH_WindowFrame_Mask, &bar, widget, &mask) && !mask.region.isEmpty();
2279 bool hasBorder = !style()->styleHint(QStyle::SH_TitleBar_NoBorder, &bar, widget);
2280 int frameWidth = style()->pixelMetric(QStyle::PM_MDIFrameWidth, &bar, widget);
2283 painter->setClipRegion(mask.region, Qt::IntersectClip);
2285 if (fillBackground) {
2286 if (embeddedWidgetFillsOwnBackground) {
2287 // Don't fill the background twice.
2288 QPainterPath windowFrameBackground;
2289 windowFrameBackground.addRect(windowFrameRect);
2290 // Adjust with 0.5 to avoid border artifacts between
2291 // widget background and frame background.
2292 windowFrameBackground.addRect(rect().translated(-styleOrigin).adjusted(0.5, 0.5, -0.5, -0.5));
2293 painter->fillPath(windowFrameBackground, palette().window());
2295 painter->fillRect(windowFrameRect, palette().window());
2298 painter->setRenderHint(QPainter::NonCosmeticDefaultPen);
2301 int height = (int)d->titleBarHeight(bar);
2302 bar.rect.setHeight(height);
2303 if (hasBorder) // Frame is painted by PE_FrameWindow
2304 bar.rect.adjust(frameWidth, frameWidth, -frameWidth, 0);
2307 painter->setFont(QApplication::font("QWorkspaceTitleBar"));
2308 style()->drawComplexControl(QStyle::CC_TitleBar, &bar, painter, widget);
2312 // Draw window frame
2313 QStyleOptionFrame frameOptions;
2314 frameOptions.QStyleOption::operator=(*option);
2315 initStyleOption(&frameOptions);
2317 painter->setClipRect(windowFrameRect.adjusted(0, +height, 0, 0), Qt::IntersectClip);
2319 frameOptions.state |= QStyle::State_HasFocus;
2321 frameOptions.state &= ~QStyle::State_HasFocus;
2323 bool isActive = isActiveWindow();
2325 frameOptions.state |= QStyle::State_Active;
2327 frameOptions.state &= ~QStyle::State_Active;
2330 frameOptions.palette.setCurrentColorGroup(isActive ? QPalette::Active : QPalette::Normal);
2331 frameOptions.rect = windowFrameRect;
2332 frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, widget);
2333 frameOptions.midLineWidth = 1;
2334 style()->drawPrimitive(QStyle::PE_FrameWindow, &frameOptions, painter, widget);
2337 realPainter->drawPixmap(QPoint(), pm);
2345 QRectF QGraphicsWidget::boundingRect() const
2347 return windowFrameRect();
2353 QPainterPath QGraphicsWidget::shape() const
2356 path.addRect(rect());
2361 Call this function to close the widget.
2363 Returns true if the widget was closed; otherwise returns false.
2364 This slot will first send a QCloseEvent to the widget, which may or may
2365 not accept the event. If the event was ignored, nothing happens. If the
2366 event was accepted, it will hide() the widget.
2368 If the widget has the Qt::WA_DeleteOnClose attribute set it will be
2371 bool QGraphicsWidget::close()
2373 QCloseEvent closeEvent;
2374 QApplication::sendEvent(this, &closeEvent);
2375 if (!closeEvent.isAccepted()) {
2382 if (testAttribute(Qt::WA_DeleteOnClose)) {
2388 #ifdef Q_NO_USING_KEYWORD
2390 \fn const QObjectList &QGraphicsWidget::children() const
2393 This function returns the same value as QObject::children(). It's
2394 provided to differentiate between the obsolete member
2395 QGraphicsItem::children() and QObject::children(). QGraphicsItem now
2396 provides childItems() instead.
2401 void QGraphicsWidget::dumpFocusChain()
2403 qDebug() << "=========== Dumping focus chain ==============";
2405 QGraphicsWidget *next = this;
2406 QSet<QGraphicsWidget*> visited;
2409 qWarning("Found a focus chain that is not circular, (next == 0)");
2412 qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromAscii("focusItem:%1").arg(next->hasFocus() ? '1' : '0') << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0);
2413 if (visited.contains(next)) {
2414 qWarning("Already visited this node. However, I expected to dump until I found myself.");
2418 next = next->d_func()->focusNext;
2419 } while (next != this);
2425 #endif //QT_NO_GRAPHICSVIEW