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 void setWindowIconText_sys(
const QString &cap);
403 void setWindowIconText_helper(
const QString &cap);
404 void setWindowTitle_sys(
const QString &cap);
405 void setWindowFilePath_sys(
const QString &filePath);
408 void setCursor_sys(
const QCursor &cursor);
409 void unsetCursor_sys();
412 void setWindowTitle_helper(
const QString &cap);
413 void setWindowFilePath_helper(
const QString &filePath);
414 void setWindowModified_helper();
415 virtual void setWindowFlags(Qt::WindowFlags windowFlags);
417 bool setMinimumSize_helper(
int &minw,
int &minh);
418 bool setMaximumSize_helper(
int &maxw,
int &maxh);
419 void setConstraints_sys();
420 bool pointInsideRectAndMask(
const QPointF &)
const;
421 QWidget *childAt_helper(
const QPointF &,
bool)
const;
422 QWidget *childAtRecursiveHelper(
const QPointF &p,
bool)
const;
423 void updateGeometry_helper(
bool forceUpdate);
425 void getLayoutItemMargins(
int *left,
int *top,
int *right,
int *bottom)
const;
426 void setLayoutItemMargins(
int left,
int top,
int right,
int bottom);
427 void setLayoutItemMargins(QStyle::SubElement element,
const QStyleOption *opt =
nullptr);
429 void updateContentsRect();
430 QMargins safeAreaMargins()
const;
435 virtual void aboutToDestroy() {}
438 virtual void recreate()
445 inline QWidget *effectiveFocusWidget() {
446 QWidget *w = q_func();
447 while (w->focusProxy())
456 static QWidget *parentGraphicsView(
const QWidget *widget)
458#if QT_CONFIG(graphicsview)
459 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
462 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() !=
nullptr) {
463 if (!ancestorProxy->scene()->views().empty()) {
464 return ancestorProxy->scene()->views().at(0);
474 static QRect screenGeometry(
const QWidget *widget)
476 return screenGeometry(widget, QPoint(),
false);
479 static QRect availableScreenGeometry(
const QWidget *widget)
481 return availableScreenGeometry(widget, QPoint(),
false);
484 static QScreen *screen(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
486 while (QWidget *view = parentGraphicsView(widget))
489 QScreen *screen =
nullptr;
491 screen = widget->screen()->virtualSiblingAt(globalPosition);
493 screen = widget->screen();
498 static QRect screenGeometry(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
500 return screen(widget, globalPosition, hasPosition)->geometry();
503 static QRect availableScreenGeometry(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
505 return screen(widget, globalPosition, hasPosition)->availableGeometry();
508 inline void setRedirected(QPaintDevice *replacement,
const QPoint &offset)
510 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
511 redirectDev = replacement;
512 redirectOffset = offset;
515 inline QPaintDevice *redirected(QPoint *offset)
const
518 *offset = redirectDev ? redirectOffset : QPoint();
522 inline void restoreRedirected()
523 { redirectDev =
nullptr; }
525 inline void enforceNativeChildren()
530 if (extra->nativeChildrenForced)
532 extra->nativeChildrenForced = 1;
534 for (
int i = 0; i < children.size(); ++i) {
535 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
536 child->setAttribute(Qt::WA_NativeWindow);
540 inline bool nativeChildrenForced()
const
542 return extra ? extra->nativeChildrenForced :
false;
545 inline QRect effectiveRectFor(
const QRegion ®ion)
const
547 return effectiveRectFor(region.boundingRect());
550 inline QRect effectiveRectFor(
const QRect &rect)
const
552#if QT_CONFIG(graphicseffect)
553 if (graphicsEffect && graphicsEffect->isEnabled())
554 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
559 QSize adjustedSize()
const;
561 inline void handleSoftwareInputPanel(Qt::MouseButton button,
bool clickCausedFocus)
563 if (button == Qt::LeftButton)
564 handleSoftwareInputPanel(clickCausedFocus);
567 inline void handleSoftwareInputPanel(
bool clickCausedFocus =
false)
570 if (qApp->autoSipEnabled()) {
571 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
572 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel,
nullptr, q));
573 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
574 QGuiApplication::inputMethod()->show();
579 void setWSGeometry();
581 inline QPoint mapToWS(
const QPoint &p)
const
582 {
return p - data.wrect.topLeft(); }
584 inline QPoint mapFromWS(
const QPoint &p)
const
585 {
return p + data.wrect.topLeft(); }
587 inline QRect mapToWS(
const QRect &r)
const
588 {
return r.translated(-data.wrect.topLeft()); }
590 inline QRect mapFromWS(
const QRect &r)
const
591 {
return r.translated(data.wrect.topLeft()); }
593 virtual QObject *focusObject();
595 virtual QPlatformBackingStoreRhiConfig rhiConfig()
const {
return {}; }
599 QRhiTexture *textureLeft =
nullptr;
600 QRhiTexture *textureRight =
nullptr;
603 virtual TextureData texture()
const {
return {}; }
604 virtual QPlatformTextureList::Flags textureListFlags() {
606 return q->testAttribute(Qt::WA_AlwaysStackOnTop)
607 ? QPlatformTextureList::StacksOnTop
608 : QPlatformTextureList::Flags();
610 virtual QImage grabFramebuffer() {
return QImage(); }
611 virtual void beginBackingStorePainting() { }
612 virtual void endBackingStorePainting() { }
613 virtual void beginCompose() { }
614 virtual void endCompose() { }
615 void setRenderToTexture() { renderToTexture =
true; setTextureChildSeen(); }
616 void setTextureChildSeen()
619 if (textureChildSeen)
621 textureChildSeen = 1;
623 if (!q->isWindow()) {
624 QWidget *parent = q->parentWidget();
626 get(parent)->setTextureChildSeen();
629 static void sendComposeStatus(QWidget *w,
bool end);
631 virtual void initializeViewportFramebuffer() { }
635 virtual void resizeViewportFramebuffer() { }
637 virtual void resolveSamples() { }
641 virtual bool isStereoEnabled() {
return false; }
642 virtual bool toggleStereoTargetBuffer() {
return false; }
644 static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
646 std::string flagsForDumping()
const override;
648 QWidget *closestParentWidgetWithWindowHandle()
const;
652 std::unique_ptr<QWExtra> extra;
655 QWidget *focus_child;
658 QPaintDevice *redirectDev;
659 QWidgetItemV2 *widgetItem;
660 QPaintEngine *extraPaintEngine;
661 mutable const QMetaObject *polished;
662 QGraphicsEffect *graphicsEffect;
665 QVarLengthArray<QLabel *, 1> labels;
670 static QWidgetMapper *mapper;
671 static QWidgetSet *allWidgets;
672#if !defined(QT_NO_IM)
673 Qt::InputMethodHints imHints;
677 QRegion opaqueChildren;
679#if QT_CONFIG(tooltip)
683#if QT_CONFIG(statustip)
686#if QT_CONFIG(whatsthis)
689#if QT_CONFIG(accessibility)
690 QString accessibleName;
691 QString accessibleDescription;
692 QString accessibleIdentifier;
696 uint directFontResolveMask;
697 uint inheritedFontResolveMask;
698 decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
699 QPalette::ResolveMask inheritedPaletteResolveMask;
704 signed char leftLayoutItemMargin;
705 signed char topLayoutItemMargin;
706 signed char rightLayoutItemMargin;
707 signed char bottomLayoutItemMargin;
708 static int instanceCounter;
709 static int maxInstances;
712 QSizePolicy size_policy;
714 QPoint redirectOffset;
716 QList<QAction*> actions;
718#ifndef QT_NO_GESTURES
719 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
723 uint high_attributes[4];
724 QPalette::ColorRole fg_role : 8;
725 QPalette::ColorRole bg_role : 8;
726 uint dirtyOpaqueChildren : 1;
728 uint retainSizeWhenHiddenChanged : 1;
729 uint inDirtyList : 1;
732 uint usesDoubleBufferedGLContext : 1;
733 uint mustHaveWindowHandle : 1;
734 uint renderToTexture : 1;
735 uint textureChildSeen : 1;
737 uint inheritsInputMethodHints : 1;
739 uint renderToTextureReallyDirty : 1;
740 uint usesRhiFlush : 1;
741 uint childrenHiddenByWState : 1;
742 uint childrenShownByExpose : 1;
743 uint dontSetExplicitShowHide : 1;
744 uint inheritStyleRecursionGuard : 1;
747 enum class FocusDirection {
752 enum class FocusChainRemovalRule {
753 EnsureFocusOut = 0x01,
754 AssertConsistency = 0x02,
756 Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule)
759 QWidget *nextPrevElementInFocusChain(FocusDirection direction)
const;
762 bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(),
763 FocusDirection direction = FocusDirection::Next);
764 bool insertIntoFocusChain(FocusDirection direction, QWidget *position);
765 static bool insertIntoFocusChain(
const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position);
766 bool insertIntoFocusChainBefore(QWidget *position)
767 {
return insertIntoFocusChain(FocusDirection::Previous, position); }
768 bool insertIntoFocusChainAfter(QWidget *position)
769 {
return insertIntoFocusChain(FocusDirection::Next, position); }
770 static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to,
771 FocusDirection direction = FocusDirection::Next);
772 void reparentFocusChildren(FocusDirection direction);
773 QWidget *determineLastFocusChild(QWidget *noFurtherThan);
776 void initFocusChain();
777 bool isInFocusChain()
const;
778 bool isFocusChainConsistent()
const;
782 uint noPaintOnScreen : 1;
783#elif defined(Q_OS_MACOS)
784 void macUpdateSizeAttribute();
786 void setNetWmWindowTypes(
bool skipIfMissing =
false);
788 bool stealKeyboardGrab(
bool grab);
789 bool stealMouseGrab(
bool grab);
790 bool hasChildWithFocusPolicy(Qt::FocusPolicy policy,
const QWidget *excludeChildrenOf =
nullptr)
const;