185 Q_DECLARE_PUBLIC(QWidget)
190 enum DrawWidgetFlag {
192 DrawPaintOnScreen = 0x02,
193 DrawRecursive = 0x04,
194 DrawInvisible = 0x08,
195 DontSubtractOpaqueChildren = 0x10,
196 DontDrawOpaqueChildren = 0x20,
197 DontDrawNativeChildren = 0x40,
198 DontSetCompositionMode = 0x80,
199 UseEffectRegionBounds = 0x100
201 Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag)
202 Q_FLAG(DrawWidgetFlags)
205 DirectionNorth = 0x01,
206 DirectionEast = 0x10,
207 DirectionSouth = 0x02,
213 explicit QWidgetPrivate(
decltype(QObjectPrivateVersion) = QObjectPrivateVersion);
216 static QWidgetPrivate *get(QWidget *w) {
return w->d_func(); }
217 static const QWidgetPrivate *get(
const QWidget *w) {
return w->d_func(); }
219 static void checkRestoredGeometry(
const QRect &availableGeometry, QRect *restoredGeometry,
222 QWExtra *extraData()
const;
223 QTLWExtra *topData()
const;
224 QTLWExtra *maybeTopData()
const;
225 QPainter *sharedPainter()
const;
226 void setSharedPainter(QPainter *painter);
227 QWidgetRepaintManager *maybeRepaintManager()
const;
231 enum class WindowHandleMode {
236 QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct)
const;
237 QWindow *_q_closestWindowHandle()
const;
239 QScreen *associatedScreen()
const;
241 template <
typename T>
244 template <
typename T>
247 void init(QWidget *desktopWidget, Qt::WindowFlags f);
249 void createRecursively();
252 bool setScreenForPoint(
const QPoint &pos);
253 bool setScreen(QScreen *screen);
255 void createTLExtra();
258 void createSysExtra();
259 void deleteSysExtra();
260 void createTLSysExtra();
261 void deleteTLSysExtra();
262 void updateSystemBackground();
263 void propagatePaletteChange();
265 void setPalette_helper(
const QPalette &);
266 void resolvePalette();
267 QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask)
const;
269 void setMask_sys(
const QRegion &);
273 void stackUnder_sys(QWidget *);
275 QWidget *deepestFocusProxy()
const;
277 void updateFocusChild();
279 void updateFont(
const QFont &);
280 inline void setFont_helper(
const QFont &font) {
281 if (directFontResolveMask == font.resolveMask() && data.fnt == font)
285 QFont localFont()
const;
287 QFont naturalWidgetFont(uint inheritedMask)
const;
289 void setLayoutDirection_helper(Qt::LayoutDirection);
290 void resolveLayoutDirection();
292 void setLocale_helper(
const QLocale &l,
bool forceUpdate =
false);
293 void resolveLocale();
295 void setStyle_helper(QStyle *newStyle,
bool propagate);
298 void setUpdatesEnabled_helper(
bool );
300 bool updateBrushOrigin(QPainter *,
const QBrush &brush)
const;
301 void paintBackground(QPainter *,
const QRegion &, DrawWidgetFlags flags = DrawAsRoot)
const;
302 bool isAboutToShow()
const;
303 QRegion prepareToRender(
const QRegion ®ion, QWidget::RenderFlags renderFlags);
304 void render_helper(QPainter *painter,
const QPoint &targetOffset,
const QRegion &sourceRegion,
305 QWidget::RenderFlags renderFlags);
306 void render(QPaintDevice *target,
const QPoint &targetOffset,
const QRegion &sourceRegion,
307 QWidget::RenderFlags renderFlags);
308 void drawWidget(QPaintDevice *pdev,
const QRegion &rgn,
const QPoint &offset, DrawWidgetFlags flags,
309 QPainter *sharedPainter =
nullptr, QWidgetRepaintManager *repaintManager =
nullptr);
310 void sendPaintEvent(
const QRegion &toBePainted);
313 void paintSiblingsRecursive(QPaintDevice *pdev,
const QObjectList& children,
int index,
314 const QRegion &rgn,
const QPoint &offset, DrawWidgetFlags flags,
315 QPainter *sharedPainter, QWidgetRepaintManager *repaintManager);
317#if QT_CONFIG(graphicsview)
318 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(
const QWidget *origin);
320 bool shouldPaintOnScreen()
const;
321 void paintOnScreen(
const QRegion &rgn);
323 QRect clipRect()
const;
324 QRegion clipRegion()
const;
325 void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio,
const QRegion ®ion);
326 void subtractOpaqueChildren(QRegion &rgn,
const QRect &clipRect)
const;
327 void subtractOpaqueSiblings(QRegion &source,
bool *hasDirtySiblingsAbove =
nullptr,
328 bool alsoNonOpaque =
false)
const;
329 void clipToEffectiveMask(QRegion ®ion)
const;
330 void updateIsOpaque();
331 void setOpaque(
bool opaque);
332 void updateIsTranslucent();
333#if QT_CONFIG(graphicseffect)
334 void invalidateGraphicsEffectsRecursively();
337 const QRegion &getOpaqueChildren()
const;
338 void setDirtyOpaqueRegion();
344 CloseWithSpontaneousEvent
347 bool handleClose(CloseMode mode);
349 void setWindowIcon_helper();
350 void setWindowIcon_sys();
351 void setWindowOpacity_sys(qreal opacity);
352 void adjustQuitOnCloseAttribute();
354 void scrollChildren(
int dx,
int dy);
355 void moveRect(
const QRect &,
int dx,
int dy);
356 void scrollRect(
const QRect &,
int dx,
int dy);
357 void invalidateBackingStore_resizeHelper(
const QPoint &oldPos,
const QSize &oldSize);
360 void invalidateBackingStore(
const T &);
362 QRegion overlappedRegion(
const QRect &rect,
bool breakAfterFirst =
false)
const;
363 bool isOverlapped(
const QRect &rect)
const {
return !overlappedRegion(rect,
true).isEmpty(); }
364 void syncBackingStore();
365 void syncBackingStore(
const QRegion ®ion);
367 bool shouldDiscardSyncRequest()
const;
370 void updateWidgetTransform(QEvent *event);
372 void reparentFocusWidgets(QWidget *oldtlw);
375 void showChildren(
bool spontaneous);
376 void hideChildren(
bool spontaneous);
377 void setParent_sys(QWidget *parent, Qt::WindowFlags);
378 void reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags = {});
379 void reparentWidgetWindowChildren(QWidget *parentWithWindow);
380 void scroll_sys(
int dx,
int dy);
381 void scroll_sys(
int dx,
int dy,
const QRect &r);
382 void deactivateWidgetCleanup();
383 void setGeometry_sys(
int,
int,
int,
int,
bool);
384 void fixPosIncludesFrame();
385 void sendPendingMoveAndResizeEvents(
bool recursive =
false,
bool disableUpdates =
false);
386 void activateChildLayoutsRecursively();
387 void show_recursive();
392 bool isExplicitlyHidden()
const;
393 void _q_showIfNotHidden();
394 virtual void setVisible(
bool);
396 void setEnabled_helper(
bool);
397 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w =
nullptr);
399 void updateFrameStrut();
400 QRect frameStrut()
const;
402#ifdef QT_KEYPAD_NAVIGATION
403 static bool navigateToDirection(Direction direction);
404 static QWidget *widgetInNavigationDirection(Direction direction);
405 static bool canKeypadNavigate(Qt::Orientation orientation);
406 static bool inTabWidget(QWidget *widget);
409 void setWindowIconText_sys(
const QString &cap);
410 void setWindowIconText_helper(
const QString &cap);
411 void setWindowTitle_sys(
const QString &cap);
412 void setWindowFilePath_sys(
const QString &filePath);
415 void setCursor_sys(
const QCursor &cursor);
416 void unsetCursor_sys();
419 void setWindowTitle_helper(
const QString &cap);
420 void setWindowFilePath_helper(
const QString &filePath);
421 void setWindowModified_helper();
422 virtual void setWindowFlags(Qt::WindowFlags windowFlags);
424 bool setMinimumSize_helper(
int &minw,
int &minh);
425 bool setMaximumSize_helper(
int &maxw,
int &maxh);
426 void setConstraints_sys();
427 bool pointInsideRectAndMask(
const QPointF &)
const;
428 QWidget *childAt_helper(
const QPointF &,
bool)
const;
429 QWidget *childAtRecursiveHelper(
const QPointF &p,
bool)
const;
430 void updateGeometry_helper(
bool forceUpdate);
432 void getLayoutItemMargins(
int *left,
int *top,
int *right,
int *bottom)
const;
433 void setLayoutItemMargins(
int left,
int top,
int right,
int bottom);
434 void setLayoutItemMargins(QStyle::SubElement element,
const QStyleOption *opt =
nullptr);
436 void updateContentsRect();
437 QMargins safeAreaMargins()
const;
442 virtual void aboutToDestroy() {}
444 inline QWidget *effectiveFocusWidget() {
445 QWidget *w = q_func();
446 while (w->focusProxy())
455 static QWidget *parentGraphicsView(
const QWidget *widget)
457#if QT_CONFIG(graphicsview)
458 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
461 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() !=
nullptr) {
462 if (!ancestorProxy->scene()->views().empty()) {
463 return ancestorProxy->scene()->views().at(0);
473 static QRect screenGeometry(
const QWidget *widget)
475 return screenGeometry(widget, QPoint(),
false);
478 static QRect availableScreenGeometry(
const QWidget *widget)
480 return availableScreenGeometry(widget, QPoint(),
false);
483 static QScreen *screen(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
485 while (QWidget *view = parentGraphicsView(widget))
488 QScreen *screen =
nullptr;
490 screen = widget->screen()->virtualSiblingAt(globalPosition);
492 screen = widget->screen();
497 static QRect screenGeometry(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
499 return screen(widget, globalPosition, hasPosition)->geometry();
502 static QRect availableScreenGeometry(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
504 return screen(widget, globalPosition, hasPosition)->availableGeometry();
507 inline void setRedirected(QPaintDevice *replacement,
const QPoint &offset)
509 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
510 redirectDev = replacement;
511 redirectOffset = offset;
514 inline QPaintDevice *redirected(QPoint *offset)
const
517 *offset = redirectDev ? redirectOffset : QPoint();
521 inline void restoreRedirected()
522 { redirectDev =
nullptr; }
524 inline void enforceNativeChildren()
529 if (extra->nativeChildrenForced)
531 extra->nativeChildrenForced = 1;
533 for (
int i = 0; i < children.size(); ++i) {
534 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
535 child->setAttribute(Qt::WA_NativeWindow);
539 inline bool nativeChildrenForced()
const
541 return extra ? extra->nativeChildrenForced :
false;
544 inline QRect effectiveRectFor(
const QRegion ®ion)
const
546 return effectiveRectFor(region.boundingRect());
549 inline QRect effectiveRectFor(
const QRect &rect)
const
551#if QT_CONFIG(graphicseffect)
552 if (graphicsEffect && graphicsEffect->isEnabled())
553 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
558 QSize adjustedSize()
const;
560 inline void handleSoftwareInputPanel(Qt::MouseButton button,
bool clickCausedFocus)
562 if (button == Qt::LeftButton)
563 handleSoftwareInputPanel(clickCausedFocus);
566 inline void handleSoftwareInputPanel(
bool clickCausedFocus =
false)
569 if (
qApp->autoSipEnabled()) {
570 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
571 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel,
nullptr, q));
572 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
573 QGuiApplication::inputMethod()->show();
578 void setWSGeometry();
580 inline QPoint mapToWS(
const QPoint &p)
const
581 {
return p - data.wrect.topLeft(); }
583 inline QPoint mapFromWS(
const QPoint &p)
const
584 {
return p + data.wrect.topLeft(); }
586 inline QRect mapToWS(
const QRect &r)
const
587 {
return r.translated(-data.wrect.topLeft()); }
589 inline QRect mapFromWS(
const QRect &r)
const
590 {
return r.translated(data.wrect.topLeft()); }
592 virtual QObject *focusObject();
594 virtual QPlatformBackingStoreRhiConfig rhiConfig()
const {
return {}; }
598 QRhiTexture *textureLeft =
nullptr;
599 QRhiTexture *textureRight =
nullptr;
602 virtual TextureData texture()
const {
return {}; }
603 virtual QPlatformTextureList::Flags textureListFlags() {
605 return q->testAttribute(Qt::WA_AlwaysStackOnTop)
606 ? QPlatformTextureList::StacksOnTop
607 : QPlatformTextureList::Flags();
609 virtual QImage grabFramebuffer() {
return QImage(); }
610 virtual void beginBackingStorePainting() { }
611 virtual void endBackingStorePainting() { }
612 virtual void beginCompose() { }
613 virtual void endCompose() { }
614 void setRenderToTexture() { renderToTexture =
true; setTextureChildSeen(); }
615 void setTextureChildSeen()
618 if (textureChildSeen)
620 textureChildSeen = 1;
622 if (!q->isWindow()) {
623 QWidget *parent = q->parentWidget();
625 get(parent)->setTextureChildSeen();
628 static void sendComposeStatus(QWidget *w,
bool end);
630 virtual void initializeViewportFramebuffer() { }
634 virtual void resizeViewportFramebuffer() { }
636 virtual void resolveSamples() { }
640 virtual bool isStereoEnabled() {
return false; }
641 virtual bool toggleStereoTargetBuffer() {
return false; }
643 static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
645 std::string flagsForDumping()
const override;
647 QWidget *closestParentWidgetWithWindowHandle()
const;
651 std::unique_ptr<QWExtra> extra;
654 QWidget *focus_child;
657 QPaintDevice *redirectDev;
658 QWidgetItemV2 *widgetItem;
659 QPaintEngine *extraPaintEngine;
660 mutable const QMetaObject *polished;
661 QGraphicsEffect *graphicsEffect;
664 QVarLengthArray<QLabel *, 1> labels;
669 static QWidgetMapper *mapper;
670 static QWidgetSet *allWidgets;
671#if !defined(QT_NO_IM)
672 Qt::InputMethodHints imHints;
674#ifdef QT_KEYPAD_NAVIGATION
675 static QPointer<QWidget> editingWidget;
679 QRegion opaqueChildren;
681#if QT_CONFIG(tooltip)
685#if QT_CONFIG(statustip)
688#if QT_CONFIG(whatsthis)
691#if QT_CONFIG(accessibility)
692 QString accessibleName;
693 QString accessibleDescription;
694 QString accessibleIdentifier;
698 uint directFontResolveMask;
699 uint inheritedFontResolveMask;
700 decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
701 QPalette::ResolveMask inheritedPaletteResolveMask;
706 signed char leftLayoutItemMargin;
707 signed char topLayoutItemMargin;
708 signed char rightLayoutItemMargin;
709 signed char bottomLayoutItemMargin;
710 static int instanceCounter;
711 static int maxInstances;
714 QSizePolicy size_policy;
716 QPoint redirectOffset;
718 QList<QAction*> actions;
720#ifndef QT_NO_GESTURES
721 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
725 uint high_attributes[4];
726 QPalette::ColorRole fg_role : 8;
727 QPalette::ColorRole bg_role : 8;
728 uint dirtyOpaqueChildren : 1;
730 uint retainSizeWhenHiddenChanged : 1;
731 uint inDirtyList : 1;
734 uint usesDoubleBufferedGLContext : 1;
735 uint mustHaveWindowHandle : 1;
736 uint renderToTexture : 1;
737 uint textureChildSeen : 1;
739 uint inheritsInputMethodHints : 1;
741 uint renderToTextureReallyDirty : 1;
742 uint usesRhiFlush : 1;
743 uint childrenHiddenByWState : 1;
744 uint childrenShownByExpose : 1;
745 uint dontSetExplicitShowHide : 1;
746 uint inheritStyleRecursionGuard : 1;
749 enum class FocusDirection {
754 enum class FocusChainRemovalRule {
755 EnsureFocusOut = 0x01,
756 AssertConsistency = 0x02,
758 Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule)
761 QWidget *nextPrevElementInFocusChain(FocusDirection direction)
const;
764 bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(),
765 FocusDirection direction = FocusDirection::Next);
766 bool insertIntoFocusChain(FocusDirection direction, QWidget *position);
767 static bool insertIntoFocusChain(
const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position);
768 bool insertIntoFocusChainBefore(QWidget *position)
769 {
return insertIntoFocusChain(FocusDirection::Previous, position); }
770 bool insertIntoFocusChainAfter(QWidget *position)
771 {
return insertIntoFocusChain(FocusDirection::Next, position); }
772 static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to,
773 FocusDirection direction = FocusDirection::Next);
774 void reparentFocusChildren(FocusDirection direction);
775 QWidget *determineLastFocusChild(QWidget *noFurtherThan);
778 void initFocusChain();
779 bool isInFocusChain()
const;
780 bool isFocusChainConsistent()
const;
784 uint noPaintOnScreen : 1;
785#elif defined(Q_OS_MAC)
786 void macUpdateSizeAttribute();
788 void setNetWmWindowTypes(
bool skipIfMissing =
false);
790 bool stealKeyboardGrab(
bool grab);
791 bool stealMouseGrab(
bool grab);
792 bool hasChildWithFocusPolicy(Qt::FocusPolicy policy,
const QWidget *excludeChildrenOf =
nullptr)
const;