184 Q_DECLARE_PUBLIC(QWidget)
189 enum DrawWidgetFlag {
191 DrawPaintOnScreen = 0x02,
192 DrawRecursive = 0x04,
193 DrawInvisible = 0x08,
194 DontSubtractOpaqueChildren = 0x10,
195 DontDrawOpaqueChildren = 0x20,
196 DontDrawNativeChildren = 0x40,
197 DontSetCompositionMode = 0x80,
198 UseEffectRegionBounds = 0x100
200 Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag)
201 Q_FLAG(DrawWidgetFlags)
204 DirectionNorth = 0x01,
205 DirectionEast = 0x10,
206 DirectionSouth = 0x02,
212 explicit QWidgetPrivate(
decltype(QObjectPrivateVersion) = QObjectPrivateVersion);
215 static QWidgetPrivate *get(QWidget *w) {
return w->d_func(); }
216 static const QWidgetPrivate *get(
const QWidget *w) {
return w->d_func(); }
218 static void checkRestoredGeometry(
const QRect &availableGeometry, QRect *restoredGeometry,
221 QWExtra *extraData()
const;
222 QTLWExtra *topData()
const;
223 QTLWExtra *maybeTopData()
const;
224 QPainter *sharedPainter()
const;
225 void setSharedPainter(QPainter *painter);
226 QWidgetRepaintManager *maybeRepaintManager()
const;
230 enum class WindowHandleMode {
235 QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct)
const;
236 QWindow *_q_closestWindowHandle()
const;
238 QScreen *associatedScreen()
const;
240 template <
typename T>
243 template <
typename T>
246 void init(QWidget *desktopWidget, Qt::WindowFlags f);
248 void createRecursively();
251 bool setScreenForPoint(
const QPoint &pos);
252 bool setScreen(QScreen *screen);
254 void createTLExtra();
257 void createSysExtra();
258 void deleteSysExtra();
259 void createTLSysExtra();
260 void deleteTLSysExtra();
261 void updateSystemBackground();
262 void propagatePaletteChange();
264 void setPalette_helper(
const QPalette &);
265 void resolvePalette();
266 QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask)
const;
268 void setMask_sys(
const QRegion &);
272 void stackUnder_sys(QWidget *);
274 QWidget *deepestFocusProxy()
const;
276 void updateFocusChild();
278 void updateFont(
const QFont &);
279 inline void setFont_helper(
const QFont &font) {
280 if (directFontResolveMask == font.resolveMask() && data.fnt == font)
284 QFont localFont()
const;
286 QFont naturalWidgetFont(uint inheritedMask)
const;
288 void setLayoutDirection_helper(Qt::LayoutDirection);
289 void resolveLayoutDirection();
291 void setLocale_helper(
const QLocale &l,
bool forceUpdate =
false);
292 void resolveLocale();
294 void setStyle_helper(QStyle *newStyle,
bool propagate);
297 void setUpdatesEnabled_helper(
bool );
299 bool updateBrushOrigin(QPainter *,
const QBrush &brush)
const;
300 void paintBackground(QPainter *,
const QRegion &, DrawWidgetFlags flags = DrawAsRoot)
const;
301 bool isAboutToShow()
const;
302 QRegion prepareToRender(
const QRegion ®ion, QWidget::RenderFlags renderFlags);
303 void render_helper(QPainter *painter,
const QPoint &targetOffset,
const QRegion &sourceRegion,
304 QWidget::RenderFlags renderFlags);
305 void render(QPaintDevice *target,
const QPoint &targetOffset,
const QRegion &sourceRegion,
306 QWidget::RenderFlags renderFlags);
307 void drawWidget(QPaintDevice *pdev,
const QRegion &rgn,
const QPoint &offset, DrawWidgetFlags flags,
308 QPainter *sharedPainter =
nullptr, QWidgetRepaintManager *repaintManager =
nullptr);
309 void sendPaintEvent(
const QRegion &toBePainted);
312 void paintSiblingsRecursive(QPaintDevice *pdev,
const QObjectList& children,
int index,
313 const QRegion &rgn,
const QPoint &offset, DrawWidgetFlags flags,
314 QPainter *sharedPainter, QWidgetRepaintManager *repaintManager);
316#if QT_CONFIG(graphicsview)
317 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(
const QWidget *origin);
319 bool shouldPaintOnScreen()
const;
320 void paintOnScreen(
const QRegion &rgn);
322 QRect clipRect()
const;
323 QRegion clipRegion()
const;
324 void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio,
const QRegion ®ion);
325 void subtractOpaqueChildren(QRegion &rgn,
const QRect &clipRect)
const;
326 void subtractOpaqueSiblings(QRegion &source,
bool *hasDirtySiblingsAbove =
nullptr,
327 bool alsoNonOpaque =
false)
const;
328 void clipToEffectiveMask(QRegion ®ion)
const;
329 void updateIsOpaque();
330 void setOpaque(
bool opaque);
331 void updateIsTranslucent();
332#if QT_CONFIG(graphicseffect)
333 void invalidateGraphicsEffectsRecursively();
336 const QRegion &getOpaqueChildren()
const;
337 void setDirtyOpaqueRegion();
343 CloseWithSpontaneousEvent
346 bool handleClose(CloseMode mode);
348 void setWindowIcon_helper();
349 void setWindowIcon_sys();
350 void setWindowOpacity_sys(qreal opacity);
351 void adjustQuitOnCloseAttribute();
353 void scrollChildren(
int dx,
int dy);
354 void moveRect(
const QRect &,
int dx,
int dy);
355 void scrollRect(
const QRect &,
int dx,
int dy);
356 void invalidateBackingStore_resizeHelper(
const QPoint &oldPos,
const QSize &oldSize);
359 void invalidateBackingStore(
const T &);
361 QRegion overlappedRegion(
const QRect &rect,
bool breakAfterFirst =
false)
const;
362 bool isOverlapped(
const QRect &rect)
const {
return !overlappedRegion(rect,
true).isEmpty(); }
363 void syncBackingStore();
364 void syncBackingStore(
const QRegion ®ion);
366 bool shouldDiscardSyncRequest()
const;
369 void updateWidgetTransform(QEvent *event);
371 void reparentFocusWidgets(QWidget *oldtlw);
374 void showChildren(
bool spontaneous);
375 void hideChildren(
bool spontaneous);
376 void setParent_sys(QWidget *parent, Qt::WindowFlags);
377 void reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags = {});
378 void reparentWidgetWindowChildren(QWidget *parentWithWindow);
379 void scroll_sys(
int dx,
int dy);
380 void scroll_sys(
int dx,
int dy,
const QRect &r);
381 void deactivateWidgetCleanup();
382 void setGeometry_sys(
int,
int,
int,
int,
bool);
383 void fixPosIncludesFrame();
384 void sendPendingMoveAndResizeEvents(
bool recursive =
false,
bool disableUpdates =
false);
385 void activateChildLayoutsRecursively();
386 void show_recursive();
391 bool isExplicitlyHidden()
const;
392 void _q_showIfNotHidden();
393 virtual void setVisible(
bool);
395 void setEnabled_helper(
bool);
396 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w =
nullptr);
398 void updateFrameStrut();
399 QRect frameStrut()
const;
401 void setWindowIconText_sys(
const QString &cap);
402 void setWindowIconText_helper(
const QString &cap);
403 void setWindowTitle_sys(
const QString &cap);
404 void setWindowFilePath_sys(
const QString &filePath);
407 void setCursor_sys(
const QCursor &cursor);
408 void unsetCursor_sys();
411 void setWindowTitle_helper(
const QString &cap);
412 void setWindowFilePath_helper(
const QString &filePath);
413 void setWindowModified_helper();
414 virtual void setWindowFlags(Qt::WindowFlags windowFlags);
416 bool setMinimumSize_helper(
int &minw,
int &minh);
417 bool setMaximumSize_helper(
int &maxw,
int &maxh);
418 void setConstraints_sys();
419 bool pointInsideRectAndMask(
const QPointF &)
const;
420 QWidget *childAt_helper(
const QPointF &,
bool)
const;
421 QWidget *childAtRecursiveHelper(
const QPointF &p,
bool)
const;
422 void updateGeometry_helper(
bool forceUpdate);
424 void getLayoutItemMargins(
int *left,
int *top,
int *right,
int *bottom)
const;
425 void setLayoutItemMargins(
int left,
int top,
int right,
int bottom);
426 void setLayoutItemMargins(QStyle::SubElement element,
const QStyleOption *opt =
nullptr);
428 void updateContentsRect();
429 QMargins safeAreaMargins()
const;
434 virtual void aboutToDestroy() {}
437 virtual void recreate()
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;
676 QRegion opaqueChildren;
678#if QT_CONFIG(tooltip)
680 std::chrono::milliseconds toolTipDuration;
682#if QT_CONFIG(statustip)
685#if QT_CONFIG(whatsthis)
688#if QT_CONFIG(accessibility)
689 QString accessibleName;
690 QString accessibleDescription;
691 QString accessibleIdentifier;
695 uint directFontResolveMask;
696 uint inheritedFontResolveMask;
697 decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
698 QPalette::ResolveMask inheritedPaletteResolveMask;
703 signed char leftLayoutItemMargin;
704 signed char topLayoutItemMargin;
705 signed char rightLayoutItemMargin;
706 signed char bottomLayoutItemMargin;
707 static int instanceCounter;
708 static int maxInstances;
711 QSizePolicy size_policy;
713 QPoint redirectOffset;
715 QList<QAction*> actions;
717#ifndef QT_NO_GESTURES
718 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
722 uint high_attributes[4];
723 QPalette::ColorRole fg_role : 8;
724 QPalette::ColorRole bg_role : 8;
725 uint dirtyOpaqueChildren : 1;
727 uint retainSizeWhenHiddenChanged : 1;
728 uint inDirtyList : 1;
731 uint usesDoubleBufferedGLContext : 1;
732 uint mustHaveWindowHandle : 1;
733 uint renderToTexture : 1;
734 uint textureChildSeen : 1;
736 uint inheritsInputMethodHints : 1;
738 uint renderToTextureReallyDirty : 1;
739 uint usesRhiFlush : 1;
740 uint childrenHiddenByWState : 1;
741 uint childrenShownByExpose : 1;
742 uint dontSetExplicitShowHide : 1;
743 uint inheritStyleRecursionGuard : 1;
746 enum class FocusDirection {
751 enum class FocusChainRemovalRule {
752 EnsureFocusOut = 0x01,
753 AssertConsistency = 0x02,
755 Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule)
758 QWidget *nextPrevElementInFocusChain(FocusDirection direction)
const;
761 bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(),
762 FocusDirection direction = FocusDirection::Next);
763 bool insertIntoFocusChain(FocusDirection direction, QWidget *position);
764 static bool insertIntoFocusChain(
const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position);
765 bool insertIntoFocusChainBefore(QWidget *position)
766 {
return insertIntoFocusChain(FocusDirection::Previous, position); }
767 bool insertIntoFocusChainAfter(QWidget *position)
768 {
return insertIntoFocusChain(FocusDirection::Next, position); }
769 static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to,
770 FocusDirection direction = FocusDirection::Next);
771 void reparentFocusChildren(FocusDirection direction);
772 QWidget *determineLastFocusChild(QWidget *noFurtherThan);
775 void initFocusChain();
776 bool isInFocusChain()
const;
777 bool isFocusChainConsistent()
const;
781 uint noPaintOnScreen : 1;
782#elif defined(Q_OS_MACOS)
783 void macUpdateSizeAttribute();
785 void setNetWmWindowTypes(
bool skipIfMissing =
false);
787 bool stealKeyboardGrab(
bool grab);
788 bool stealMouseGrab(
bool grab);
789 bool hasChildWithFocusPolicy(Qt::FocusPolicy policy,
const QWidget *excludeChildrenOf =
nullptr)
const;