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() {}
445 virtual void recreate()
452 inline QWidget *effectiveFocusWidget() {
453 QWidget *w = q_func();
454 while (w->focusProxy())
463 static QWidget *parentGraphicsView(
const QWidget *widget)
465#if QT_CONFIG(graphicsview)
466 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
469 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() !=
nullptr) {
470 if (!ancestorProxy->scene()->views().empty()) {
471 return ancestorProxy->scene()->views().at(0);
481 static QRect screenGeometry(
const QWidget *widget)
483 return screenGeometry(widget, QPoint(),
false);
486 static QRect availableScreenGeometry(
const QWidget *widget)
488 return availableScreenGeometry(widget, QPoint(),
false);
491 static QScreen *screen(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
493 while (QWidget *view = parentGraphicsView(widget))
496 QScreen *screen =
nullptr;
498 screen = widget->screen()->virtualSiblingAt(globalPosition);
500 screen = widget->screen();
505 static QRect screenGeometry(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
507 return screen(widget, globalPosition, hasPosition)->geometry();
510 static QRect availableScreenGeometry(
const QWidget *widget,
const QPoint &globalPosition,
bool hasPosition =
true)
512 return screen(widget, globalPosition, hasPosition)->availableGeometry();
515 inline void setRedirected(QPaintDevice *replacement,
const QPoint &offset)
517 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
518 redirectDev = replacement;
519 redirectOffset = offset;
522 inline QPaintDevice *redirected(QPoint *offset)
const
525 *offset = redirectDev ? redirectOffset : QPoint();
529 inline void restoreRedirected()
530 { redirectDev =
nullptr; }
532 inline void enforceNativeChildren()
537 if (extra->nativeChildrenForced)
539 extra->nativeChildrenForced = 1;
541 for (
int i = 0; i < children.size(); ++i) {
542 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
543 child->setAttribute(Qt::WA_NativeWindow);
547 inline bool nativeChildrenForced()
const
549 return extra ? extra->nativeChildrenForced :
false;
552 inline QRect effectiveRectFor(
const QRegion ®ion)
const
554 return effectiveRectFor(region.boundingRect());
557 inline QRect effectiveRectFor(
const QRect &rect)
const
559#if QT_CONFIG(graphicseffect)
560 if (graphicsEffect && graphicsEffect->isEnabled())
561 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
566 QSize adjustedSize()
const;
568 inline void handleSoftwareInputPanel(Qt::MouseButton button,
bool clickCausedFocus)
570 if (button == Qt::LeftButton)
571 handleSoftwareInputPanel(clickCausedFocus);
574 inline void handleSoftwareInputPanel(
bool clickCausedFocus =
false)
577 if (qApp->autoSipEnabled()) {
578 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
579 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel,
nullptr, q));
580 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
581 QGuiApplication::inputMethod()->show();
586 void setWSGeometry();
588 inline QPoint mapToWS(
const QPoint &p)
const
589 {
return p - data.wrect.topLeft(); }
591 inline QPoint mapFromWS(
const QPoint &p)
const
592 {
return p + data.wrect.topLeft(); }
594 inline QRect mapToWS(
const QRect &r)
const
595 {
return r.translated(-data.wrect.topLeft()); }
597 inline QRect mapFromWS(
const QRect &r)
const
598 {
return r.translated(data.wrect.topLeft()); }
600 virtual QObject *focusObject();
602 virtual QPlatformBackingStoreRhiConfig rhiConfig()
const {
return {}; }
606 QRhiTexture *textureLeft =
nullptr;
607 QRhiTexture *textureRight =
nullptr;
610 virtual TextureData texture()
const {
return {}; }
611 virtual QPlatformTextureList::Flags textureListFlags() {
613 return q->testAttribute(Qt::WA_AlwaysStackOnTop)
614 ? QPlatformTextureList::StacksOnTop
615 : QPlatformTextureList::Flags();
617 virtual QImage grabFramebuffer() {
return QImage(); }
618 virtual void beginBackingStorePainting() { }
619 virtual void endBackingStorePainting() { }
620 virtual void beginCompose() { }
621 virtual void endCompose() { }
622 void setRenderToTexture() { renderToTexture =
true; setTextureChildSeen(); }
623 void setTextureChildSeen()
626 if (textureChildSeen)
628 textureChildSeen = 1;
630 if (!q->isWindow()) {
631 QWidget *parent = q->parentWidget();
633 get(parent)->setTextureChildSeen();
636 static void sendComposeStatus(QWidget *w,
bool end);
638 virtual void initializeViewportFramebuffer() { }
642 virtual void resizeViewportFramebuffer() { }
644 virtual void resolveSamples() { }
648 virtual bool isStereoEnabled() {
return false; }
649 virtual bool toggleStereoTargetBuffer() {
return false; }
651 static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
653 std::string flagsForDumping()
const override;
655 QWidget *closestParentWidgetWithWindowHandle()
const;
659 std::unique_ptr<QWExtra> extra;
662 QWidget *focus_child;
665 QPaintDevice *redirectDev;
666 QWidgetItemV2 *widgetItem;
667 QPaintEngine *extraPaintEngine;
668 mutable const QMetaObject *polished;
669 QGraphicsEffect *graphicsEffect;
672 QVarLengthArray<QLabel *, 1> labels;
677 static QWidgetMapper *mapper;
678 static QWidgetSet *allWidgets;
679#if !defined(QT_NO_IM)
680 Qt::InputMethodHints imHints;
682#ifdef QT_KEYPAD_NAVIGATION
683 static QPointer<QWidget> editingWidget;
687 QRegion opaqueChildren;
689#if QT_CONFIG(tooltip)
693#if QT_CONFIG(statustip)
696#if QT_CONFIG(whatsthis)
699#if QT_CONFIG(accessibility)
700 QString accessibleName;
701 QString accessibleDescription;
702 QString accessibleIdentifier;
706 uint directFontResolveMask;
707 uint inheritedFontResolveMask;
708 decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
709 QPalette::ResolveMask inheritedPaletteResolveMask;
714 signed char leftLayoutItemMargin;
715 signed char topLayoutItemMargin;
716 signed char rightLayoutItemMargin;
717 signed char bottomLayoutItemMargin;
718 static int instanceCounter;
719 static int maxInstances;
722 QSizePolicy size_policy;
724 QPoint redirectOffset;
726 QList<QAction*> actions;
728#ifndef QT_NO_GESTURES
729 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
733 uint high_attributes[4];
734 QPalette::ColorRole fg_role : 8;
735 QPalette::ColorRole bg_role : 8;
736 uint dirtyOpaqueChildren : 1;
738 uint retainSizeWhenHiddenChanged : 1;
739 uint inDirtyList : 1;
742 uint usesDoubleBufferedGLContext : 1;
743 uint mustHaveWindowHandle : 1;
744 uint renderToTexture : 1;
745 uint textureChildSeen : 1;
747 uint inheritsInputMethodHints : 1;
749 uint renderToTextureReallyDirty : 1;
750 uint usesRhiFlush : 1;
751 uint childrenHiddenByWState : 1;
752 uint childrenShownByExpose : 1;
753 uint dontSetExplicitShowHide : 1;
754 uint inheritStyleRecursionGuard : 1;
757 enum class FocusDirection {
762 enum class FocusChainRemovalRule {
763 EnsureFocusOut = 0x01,
764 AssertConsistency = 0x02,
766 Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule)
769 QWidget *nextPrevElementInFocusChain(FocusDirection direction)
const;
772 bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(),
773 FocusDirection direction = FocusDirection::Next);
774 bool insertIntoFocusChain(FocusDirection direction, QWidget *position);
775 static bool insertIntoFocusChain(
const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position);
776 bool insertIntoFocusChainBefore(QWidget *position)
777 {
return insertIntoFocusChain(FocusDirection::Previous, position); }
778 bool insertIntoFocusChainAfter(QWidget *position)
779 {
return insertIntoFocusChain(FocusDirection::Next, position); }
780 static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to,
781 FocusDirection direction = FocusDirection::Next);
782 void reparentFocusChildren(FocusDirection direction);
783 QWidget *determineLastFocusChild(QWidget *noFurtherThan);
786 void initFocusChain();
787 bool isInFocusChain()
const;
788 bool isFocusChainConsistent()
const;
792 uint noPaintOnScreen : 1;
793#elif defined(Q_OS_MACOS)
794 void macUpdateSizeAttribute();
796 void setNetWmWindowTypes(
bool skipIfMissing =
false);
798 bool stealKeyboardGrab(
bool grab);
799 bool stealMouseGrab(
bool grab);
800 bool hasChildWithFocusPolicy(Qt::FocusPolicy policy,
const QWidget *excludeChildrenOf =
nullptr)
const;