Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwidget_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWIDGET_P_H
5#define QWIDGET_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
13// file may change from version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18
19
20#include <QtWidgets/private/qtwidgetsglobal_p.h>
21#include "QtWidgets/qwidget.h"
22#include "private/qobject_p.h"
23#include "QtCore/qrect.h"
24#include "QtCore/qlocale.h"
25#include "QtCore/qset.h"
26#include "QtGui/qregion.h"
27#include "QtGui/qinputmethod.h"
28#include "QtGui/qsurfaceformat.h"
29#include "QtGui/qscreen.h"
30#include "QtWidgets/qsizepolicy.h"
31#include "QtWidgets/qstyle.h"
32#include "QtWidgets/qapplication.h"
33#if QT_CONFIG(graphicseffect)
34#include <private/qgraphicseffect_p.h>
35#endif
36#if QT_CONFIG(graphicsview)
37#include "QtWidgets/qgraphicsproxywidget.h"
38#include "QtWidgets/qgraphicsscene.h"
39#include "QtWidgets/qgraphicsview.h"
40#endif
41#include <private/qgesture_p.h>
42#include <qpa/qplatformbackingstore.h>
43#include <QtGui/private/qbackingstorerhisupport_p.h>
44#include <private/qapplication_p.h>
45
46#include <QtCore/qpointer.h>
47
48#include <vector>
49#include <memory>
50
52
55
56// Extra QWidget data
57// - to minimize memory usage for members that are seldom used.
58// - top-level widgets have extra extra data to reduce cost further
59class QWidgetWindow;
60class QPaintEngine;
61class QPixmap;
64class QWidgetItemV2;
65
66class QStyle;
67
68class QUnifiedToolbarSurface;
69
70// implemented in qshortcut.cpp
73
75{
76public:
77 explicit QUpdateLaterEvent(const QRegion& paintRegion)
78 : QEvent(UpdateLater), m_region(paintRegion)
79 {
80 }
81
82 inline const QRegion &region() const { return m_region; }
83
84protected:
85 friend class QApplication;
87};
88
89struct QTLWExtra {
90 // *************************** Cross-platform variables *****************************
91
92 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
93 std::unique_ptr<QIcon> icon; // widget icon
94 std::unique_ptr<QWidgetRepaintManager> repaintManager;
98
99 // Implicit pointers (shared_null).
100 QString caption; // widget caption
101 QString iconText; // widget icon text
102 QString role; // widget role
103 QString filePath; // widget file path
104
105 // Other variables.
106 short incw, inch; // size increments
107 short basew, baseh; // base sizes
108 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
110 QRect normalGeometry; // used by showMin/maximized/FullScreen
111 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
112 QScreen *initialScreen; // Screen when passing a QDesktop[Screen]Widget as parent.
113
114 std::vector<std::unique_ptr<QPlatformTextureList>> widgetTextures;
115
116 // *************************** Cross-platform bit fields ****************************
121};
122
123struct QWExtra {
124 // *************************** Cross-platform variables *****************************
125
126 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
127 void *glContext; // if the widget is hijacked by QGLWindowSurface
128 std::unique_ptr<QTLWExtra> topextra; // only useful for TLWs
129#if QT_CONFIG(graphicsview)
130 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
131#endif
132#ifndef QT_NO_CURSOR
133 std::unique_ptr<QCursor> curs;
134#endif
135 QPointer<QStyle> style;
136 QPointer<QWidget> focus_proxy;
137
138 // Implicit pointers (shared_empty/shared_null).
139 QRegion mask; // widget mask
141
142 // Other variables.
144 qint32 minh; // minimum size
146 qint32 maxh; // maximum size
150
151 // *************************** Cross-platform bit fields ****************************
159};
160
169static inline bool bypassGraphicsProxyWidget(const QWidget *p)
170{
171 while (p) {
172 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
173 return true;
174 p = p->parentWidget();
175 }
176 return false;
177}
178
179class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
180{
181 Q_DECLARE_PUBLIC(QWidget)
183
184public:
185 // *************************** Cross-platform ***************************************
187 DrawAsRoot = 0x01,
188 DrawPaintOnScreen = 0x02,
189 DrawRecursive = 0x04,
190 DrawInvisible = 0x08,
191 DontSubtractOpaqueChildren = 0x10,
192 DontDrawOpaqueChildren = 0x20,
193 DontDrawNativeChildren = 0x40,
194 DontSetCompositionMode = 0x80,
195 UseEffectRegionBounds = 0x100
196 };
197 Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag)
198 Q_FLAG(DrawWidgetFlags)
199
201 DirectionNorth = 0x01,
202 DirectionEast = 0x10,
203 DirectionSouth = 0x02,
204 DirectionWest = 0x20
205 };
206 Q_ENUM(Direction)
207
208 // Functions.
209 explicit QWidgetPrivate(int version = QObjectPrivateVersion);
211
212 static QWidgetPrivate *get(QWidget *w) { return w->d_func(); }
213 static const QWidgetPrivate *get(const QWidget *w) { return w->d_func(); }
214
215 static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
216 int frameHeight);
217
218 QWExtra *extraData() const;
219 QTLWExtra *topData() const;
220 QTLWExtra *maybeTopData() const;
221 QPainter *sharedPainter() const;
222 void setSharedPainter(QPainter *painter);
223 QWidgetRepaintManager *maybeRepaintManager() const;
224
225 QRhi *rhi() const;
226
227 enum class WindowHandleMode {
228 Direct,
229 Closest,
230 TopLevel
231 };
232 QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct) const;
233 QWindow *_q_closestWindowHandle() const; // Private slot in QWidget
234
235 QScreen *associatedScreen() const;
236
237 template <typename T>
238 void repaint(T t);
239
240 template <typename T>
241 void update(T t);
242
243 void init(QWidget *desktopWidget, Qt::WindowFlags f);
244 void create();
245 void createRecursively();
246 void createWinId();
247
248 bool setScreenForPoint(const QPoint &pos);
249 bool setScreen(QScreen *screen);
250
251 void createTLExtra();
252 void createExtra();
253 void deleteExtra();
254 void createSysExtra();
255 void deleteSysExtra();
256 void createTLSysExtra();
257 void deleteTLSysExtra();
258 void updateSystemBackground();
259 void propagatePaletteChange();
260
261 void setPalette_helper(const QPalette &);
262 void resolvePalette();
263 QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const;
264
265 void setMask_sys(const QRegion &);
266
267 void raise_sys();
268 void lower_sys();
269 void stackUnder_sys(QWidget *);
270
271 QWidget *deepestFocusProxy() const;
272 void setFocus_sys();
273 void updateFocusChild();
274
275 void updateFont(const QFont &);
276 inline void setFont_helper(const QFont &font) {
277 if (directFontResolveMask == font.resolveMask() && data.fnt == font)
278 return;
279 updateFont(font);
280 }
281 QFont localFont() const;
282 void resolveFont();
283 QFont naturalWidgetFont(uint inheritedMask) const;
284
285 void setLayoutDirection_helper(Qt::LayoutDirection);
286 void resolveLayoutDirection();
287
288 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
289 void resolveLocale();
290
291 void setStyle_helper(QStyle *newStyle, bool propagate);
292 void inheritStyle();
293
294 void setUpdatesEnabled_helper(bool );
295
296 bool updateBrushOrigin(QPainter *, const QBrush &brush) const;
297 void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags = DrawAsRoot) const;
298 bool isAboutToShow() const;
299 QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
300 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
301 QWidget::RenderFlags renderFlags);
302 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
303 QWidget::RenderFlags renderFlags);
304 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
305 QPainter *sharedPainter = nullptr, QWidgetRepaintManager *repaintManager = nullptr);
306 void sendPaintEvent(const QRegion &toBePainted);
307
308
309 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
310 const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
311 QPainter *sharedPainter, QWidgetRepaintManager *repaintManager);
312
313#if QT_CONFIG(graphicsview)
314 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
315#endif
316 bool shouldPaintOnScreen() const;
317 void paintOnScreen(const QRegion &rgn);
318
319 QRect clipRect() const;
320 QRegion clipRegion() const;
321 void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region);
322 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
323 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = nullptr,
324 bool alsoNonOpaque = false) const;
325 void clipToEffectiveMask(QRegion &region) const;
326 void updateIsOpaque();
327 void setOpaque(bool opaque);
328 void updateIsTranslucent();
329#if QT_CONFIG(graphicseffect)
330 void invalidateGraphicsEffectsRecursively();
331#endif // QT_CONFIG(graphicseffect)
332
333 const QRegion &getOpaqueChildren() const;
334 void setDirtyOpaqueRegion();
335
336 bool close();
340 CloseWithSpontaneousEvent
341 };
342 Q_ENUM(CloseMode)
343 bool handleClose(CloseMode mode);
344
345 void setWindowIcon_helper();
346 void setWindowIcon_sys();
347 void setWindowOpacity_sys(qreal opacity);
348 void adjustQuitOnCloseAttribute();
349
350 void scrollChildren(int dx, int dy);
351 void moveRect(const QRect &, int dx, int dy);
352 void scrollRect(const QRect &, int dx, int dy);
353 void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
354
355 template <class T>
356 void invalidateBackingStore(const T &);
357
358 QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst = false) const;
359 bool isOverlapped(const QRect &rect) const { return !overlappedRegion(rect, true).isEmpty(); }
360 void syncBackingStore();
361 void syncBackingStore(const QRegion &region);
362
363 bool shouldDiscardSyncRequest() const;
364
365 // tells the input method about the widgets transform
366 void updateWidgetTransform(QEvent *event);
367
368 void reparentFocusWidgets(QWidget *oldtlw);
369
370 void setWinId(WId);
371 void showChildren(bool spontaneous);
372 void hideChildren(bool spontaneous);
373 void setParent_sys(QWidget *parent, Qt::WindowFlags);
374 void reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags = {});
375 void reparentWidgetWindowChildren(QWidget *parentWithWindow);
376 void scroll_sys(int dx, int dy);
377 void scroll_sys(int dx, int dy, const QRect &r);
378 void deactivateWidgetCleanup();
379 void setGeometry_sys(int, int, int, int, bool);
380 void fixPosIncludesFrame();
381 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
382 void activateChildLayoutsRecursively();
383 void show_recursive();
384 void show_helper();
385 void show_sys();
386 void hide_sys();
387 void hide_helper();
388 bool isExplicitlyHidden() const;
389 void _q_showIfNotHidden();
390 void setVisible(bool);
391
392 void setEnabled_helper(bool);
393 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = nullptr);
394
395 void updateFrameStrut();
396 QRect frameStrut() const;
397
398#ifdef QT_KEYPAD_NAVIGATION
399 static bool navigateToDirection(Direction direction);
400 static QWidget *widgetInNavigationDirection(Direction direction);
401 static bool canKeypadNavigate(Qt::Orientation orientation);
402 static bool inTabWidget(QWidget *widget);
403#endif
404
405 void setWindowIconText_sys(const QString &cap);
406 void setWindowIconText_helper(const QString &cap);
407 void setWindowTitle_sys(const QString &cap);
408 void setWindowFilePath_sys(const QString &filePath);
409
410#ifndef QT_NO_CURSOR
411 void setCursor_sys(const QCursor &cursor);
412 void unsetCursor_sys();
413#endif
414
415 void setWindowTitle_helper(const QString &cap);
416 void setWindowFilePath_helper(const QString &filePath);
417 void setWindowModified_helper();
418 virtual void setWindowFlags(Qt::WindowFlags windowFlags);
419
420 bool setMinimumSize_helper(int &minw, int &minh);
421 bool setMaximumSize_helper(int &maxw, int &maxh);
422 void setConstraints_sys();
423 bool pointInsideRectAndMask(const QPoint &) const;
424 QWidget *childAt_helper(const QPoint &, bool) const;
425 QWidget *childAtRecursiveHelper(const QPoint &p, bool) const;
426 void updateGeometry_helper(bool forceUpdate);
427
428 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
429 void setLayoutItemMargins(int left, int top, int right, int bottom);
430 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = nullptr);
431
432 void updateContentsRect();
433 QMargins safeAreaMargins() const;
434
435 // aboutToDestroy() is called just before the contents of
436 // QWidget::destroy() is executed. It's used to signal QWidget
437 // sub-classes that their internals are about to be released.
438 virtual void aboutToDestroy() {}
439
441 QWidget *w = q_func();
442 while (w->focusProxy())
443 w = w->focusProxy();
444 return w;
445 }
446
447 void setModal_sys();
448
449 // These helper functions return the (available) geometry for the screen
450 // the widget is on, and takes care if this one is embedded in a QGraphicsView.
452 {
453#if QT_CONFIG(graphicsview)
454 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
455 //It's embedded if it has an ancestor
456 if (ancestorProxy) {
457 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != nullptr) {
458 if (!ancestorProxy->scene()->views().empty()) {
459 return ancestorProxy->scene()->views().at(0);
460 }
461 }
462 }
463#else
465#endif
466 return nullptr;
467 }
468
470 {
471 return screenGeometry(widget, QPoint(), false);
472 }
473
475 {
476 return availableScreenGeometry(widget, QPoint(), false);
477 }
478
479 static QScreen *screen(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
480 {
481 while (QWidget *view = parentGraphicsView(widget))
482 widget = view;
483
484 QScreen *screen = nullptr;
485 if (hasPosition)
486 screen = widget->screen()->virtualSiblingAt(globalPosition);
487 if (!screen)
488 screen = widget->screen();
489
490 return screen;
491 }
492
493 static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
494 {
495 return screen(widget, globalPosition, hasPosition)->geometry();
496 }
497
498 static QRect availableScreenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
499 {
500 return screen(widget, globalPosition, hasPosition)->availableGeometry();
501 }
502
503 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
504 {
505 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
506 redirectDev = replacement;
507 redirectOffset = offset;
508 }
509
511 {
512 if (offset)
513 *offset = redirectDev ? redirectOffset : QPoint();
514 return redirectDev;
515 }
516
517 inline void restoreRedirected()
518 { redirectDev = nullptr; }
519
521 {
522 if (!extra)
523 createExtra();
524
525 if (extra->nativeChildrenForced)
526 return;
527 extra->nativeChildrenForced = 1;
528
529 for (int i = 0; i < children.size(); ++i) {
530 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
531 child->setAttribute(Qt::WA_NativeWindow);
532 }
533 }
534
535 inline bool nativeChildrenForced() const
536 {
537 return extra ? extra->nativeChildrenForced : false;
538 }
539
540 inline QRect effectiveRectFor(const QRegion &region) const
541 {
542 return effectiveRectFor(region.boundingRect());
543 }
544
545 inline QRect effectiveRectFor(const QRect &rect) const
546 {
547#if QT_CONFIG(graphicseffect)
548 if (graphicsEffect && graphicsEffect->isEnabled())
549 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
550#endif // QT_CONFIG(graphicseffect)
551 return rect;
552 }
553
554 QSize adjustedSize() const;
555
556 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
557 {
558 if (button == Qt::LeftButton)
559 handleSoftwareInputPanel(clickCausedFocus);
560 }
561
562 inline void handleSoftwareInputPanel(bool clickCausedFocus = false)
563 {
564 Q_Q(QWidget);
565 if (qApp->autoSipEnabled()) {
567 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
568 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
570 }
571 }
572 }
573
574 void setWSGeometry();
575
576 inline QPoint mapToWS(const QPoint &p) const
577 { return p - data.wrect.topLeft(); }
578
579 inline QPoint mapFromWS(const QPoint &p) const
580 { return p + data.wrect.topLeft(); }
581
582 inline QRect mapToWS(const QRect &r) const
583 { return r.translated(-data.wrect.topLeft()); }
584
585 inline QRect mapFromWS(const QRect &r) const
586 { return r.translated(data.wrect.topLeft()); }
587
588 virtual QObject *focusObject();
589
590 virtual QPlatformBackingStoreRhiConfig rhiConfig() const { return {}; }
591
592 // Note that textureRight may be null, as it's only used in stereoscopic rendering
593 struct TextureData {
594 QRhiTexture *textureLeft = nullptr;
595 QRhiTexture *textureRight = nullptr;
596 };
597
598 virtual TextureData texture() const { return {}; }
599 virtual QPlatformTextureList::Flags textureListFlags() {
600 Q_Q(QWidget);
601 return q->testAttribute(Qt::WA_AlwaysStackOnTop)
603 : QPlatformTextureList::Flags();
604 }
605 virtual QImage grabFramebuffer() { return QImage(); }
606 virtual void beginBackingStorePainting() { }
607 virtual void endBackingStorePainting() { }
608 virtual void beginCompose() { }
609 virtual void endCompose() { }
610 void setRenderToTexture() { renderToTexture = true; setTextureChildSeen(); }
612 {
613 Q_Q(QWidget);
614 if (textureChildSeen)
615 return;
616 textureChildSeen = 1;
617
618 if (!q->isWindow()) {
619 QWidget *parent = q->parentWidget();
620 if (parent)
621 get(parent)->setTextureChildSeen();
622 }
623 }
624 static void sendComposeStatus(QWidget *w, bool end);
625 // Called on setViewport().
627 // When using a QOpenGLWidget as viewport with QAbstractScrollArea, resize events are
628 // filtered away from the widget. This is fine for QGLWidget but bad for QOpenGLWidget
629 // since the fbo must be resized. We need an alternative way to notify.
630 virtual void resizeViewportFramebuffer() { }
631 // Called after each paint event.
632 virtual void resolveSamples() { }
633
634 // These two are used in QGraphicsView for supporting stereoscopic rendering with a
635 // QOpenGLWidget viewport.
636 virtual bool isStereoEnabled() { return false; } // Called in QGraphicsView::setupViewport
637 virtual bool toggleStereoTargetBuffer() { return false; } // Called in QGraphicsView::paintEvent
638
639 static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
640
641 std::string flagsForDumping() const override;
642
643 QWidget *closestParentWidgetWithWindowHandle() const;
644
645 // Variables.
646 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
647 std::unique_ptr<QWExtra> extra;
656 mutable const QMetaObject *polished;
658 // All widgets are added into the allWidgets set. Once
659 // they receive a window id they are also added to the mapper.
660 // This should just ensure that all widgets are deleted by QApplication
663#if !defined(QT_NO_IM)
664 Qt::InputMethodHints imHints;
665#endif
666#ifdef QT_KEYPAD_NAVIGATION
667 static QPointer<QWidget> editingWidget;
668#endif
669
670 // Implicit pointers (shared_null/shared_empty).
673#if QT_CONFIG(tooltip)
674 QString toolTip;
675 int toolTipDuration;
676#endif
677#if QT_CONFIG(statustip)
678 QString statusTip;
679#endif
680#if QT_CONFIG(whatsthis)
681 QString whatsThis;
682#endif
683#if QT_CONFIG(accessibility)
684 QString accessibleName;
685 QString accessibleDescription;
686#endif
687
688 // Other variables.
691 decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
701 static int instanceCounter; // Current number of widget instances
702 static int maxInstances; // Maximum number of widget instances
708#ifndef QT_NO_ACTION
709 QList<QAction*> actions;
710#endif
711#ifndef QT_NO_GESTURES
712 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
713#endif
714
715 // Bit fields.
716 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
729#ifndef QT_NO_IM
731#endif
736
737 // *************************** Focus abstraction ************************************
738 enum class FocusDirection {
739 Previous,
740 Next,
741 };
742
744 EnsureFocusOut = 0x01,
745 AssertConsistency = 0x02,
746 };
747 Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule)
748
749 // Getters
750 QWidget *nextPrevElementInFocusChain(FocusDirection direction) const;
751
752 // manipulators
753 bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(),
754 FocusDirection direction = FocusDirection::Next);
755 bool insertIntoFocusChain(FocusDirection direction, QWidget *position);
756 static bool insertIntoFocusChain(const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position);
758 { return insertIntoFocusChain(FocusDirection::Previous, position); }
760 { return insertIntoFocusChain(FocusDirection::Next, position); }
761 static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to,
762 FocusDirection direction = FocusDirection::Next);
763 void reparentFocusChildren(FocusDirection direction);
764 QWidget *determineLastFocusChild(QWidget *noFurtherThan);
765
766 // Initialization and tests
767 void initFocusChain();
768 bool isInFocusChain() const;
769 bool isFocusChainConsistent() const;
770
771 // *************************** Platform specific ************************************
772#if defined(Q_OS_WIN)
773 uint noPaintOnScreen : 1; // see qwidget.cpp ::paintEngine()
774#elif defined(Q_OS_MAC)
775 void macUpdateSizeAttribute();
776#endif
777 void setNetWmWindowTypes(bool skipIfMissing = false);
778
779 bool stealKeyboardGrab(bool grab);
780 bool stealMouseGrab(bool grab);
781 bool hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf = nullptr) const;
782};
783
784Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags)
785
787{
788 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f,
790 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {}
791
795 QWidgetPrivate::DrawWidgetFlags flags;
799};
800
801#if QT_CONFIG(graphicseffect)
802class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
803{
804public:
805 QWidgetEffectSourcePrivate(QWidget *widget)
806 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(nullptr), updateDueToGraphicsEffect(false)
807 {}
808
809 void detach() override
810 { m_widget->d_func()->graphicsEffect = nullptr; }
811
812 const QGraphicsItem *graphicsItem() const override
813 { return nullptr; }
814
815 const QWidget *widget() const override
816 { return m_widget; }
817
818 void update() override
819 {
820 updateDueToGraphicsEffect = true;
821 m_widget->update();
822 updateDueToGraphicsEffect = false;
823 }
824
825 bool isPixmap() const override
826 { return false; }
827
828 void effectBoundingRectChanged() override
829 {
830 // ### This function should take a rect parameter; then we can avoid
831 // updating too much on the parent widget.
832 if (QWidget *parent = m_widget->parentWidget())
833 parent->update();
834 else
835 update();
836 }
837
838 const QStyleOption *styleOption() const override
839 { return nullptr; }
840
841 QRect deviceRect() const override
842 { return m_widget->window()->rect(); }
843
844 QRectF boundingRect(Qt::CoordinateSystem system) const override;
845 void draw(QPainter *p) override;
847 QGraphicsEffect::PixmapPadMode mode) const override;
848
849 QWidget *m_widget;
851 QTransform lastEffectTransform;
852 bool updateDueToGraphicsEffect;
853};
854#endif // QT_CONFIG(graphicseffect)
855
857{
858 return extra.get();
859}
860
862{
863 const_cast<QWidgetPrivate *>(this)->createTLExtra();
864 return extra->topextra.get();
865}
866
868{
869 return extra ? extra->topextra.get() : nullptr;
870}
871
873{
874 Q_Q(const QWidget);
875 QTLWExtra *x = q->window()->d_func()->maybeTopData();
876 return x ? x->sharedPainter : nullptr;
877}
878
880{
881 Q_Q(QWidget);
882 QTLWExtra *x = q->window()->d_func()->topData();
883 x->sharedPainter = painter;
884}
885
887{
888 Q_Q(const QWidget);
889 return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
890 || extra->mask.contains(p));
891}
892
894{
895 Q_Q(const QWidget);
896 QTLWExtra *x = q->window()->d_func()->maybeTopData();
897 return x ? x->repaintManager.get() : nullptr;
898}
899
901
902#endif // QWIDGET_P_H
The QApplication class manages the GUI application's control flow and main settings.
The QBackingStore class provides a drawing area for QWindow.
\inmodule QtGui
Definition qbrush.h:30
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ UpdateLater
Definition qcoreevent.h:114
\reentrant
Definition qfont.h:22
uint resolveMask() const
Definition qfont.h:312
virtual const QGraphicsItem * graphicsItem() const =0
virtual bool isPixmap() const =0
virtual QRectF boundingRect(Qt::CoordinateSystem system) const =0
virtual const QStyleOption * styleOption() const =0
virtual void draw(QPainter *p)=0
virtual QRect deviceRect() const =0
virtual void effectBoundingRectChanged()=0
virtual const QWidget * widget() const =0
The QGraphicsEffect class is the base class for all graphics effects.
PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
static QInputMethod * inputMethod()
returns the input method.
\inmodule QtGui
Definition qimage.h:37
The QLayout class is the base class of geometry managers.
Definition qlayout.h:26
\inmodule QtCore
Definition qmargins.h:24
\inmodule QtCore
Definition qobject.h:103
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
quint64 ResolveMask
Definition qpalette.h:113
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:261
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
QRect boundingRect() const noexcept
Returns the bounding rectangle of this region.
\inmodule QtGui
Definition qrhi.h:895
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1804
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QRect availableGeometry
the screen's available geometry in pixels
Definition qscreen.h:46
QRect geometry
the screen's geometry in pixels
Definition qscreen.h:45
QScreen * virtualSiblingAt(QPoint point)
Returns the screen at point within the set of \l QScreen::virtualSiblings(), or nullptr if outside of...
Definition qscreen.cpp:629
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QStyleOption class stores the parameters used by QStyle functions.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
@ SH_RequestSoftwareInputPanel
Definition qstyle.h:680
RequestSoftwareInputPanel
This enum describes under what circumstances a software input panel will be requested by input capabl...
Definition qstyle.h:578
@ RSIP_OnMouseClick
Definition qstyle.h:580
SubElement
This enum represents a sub-area of a widget.
Definition qstyle.h:242
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
const QRegion & region() const
Definition qwidget_p.h:82
QUpdateLaterEvent(const QRegion &paintRegion)
Definition qwidget_p.h:77
uint mustHaveWindowHandle
Definition qwidget_p.h:726
static const QWidgetPrivate * get(const QWidget *w)
Definition qwidget_p.h:213
uint dirtyOpaqueChildren
Definition qwidget_p.h:719
const QMetaObject * polished
Definition qwidget_p.h:656
QTLWExtra * maybeTopData() const
Definition qwidget_p.h:867
QRegion * needsFlush
Definition qwidget_p.h:652
static int instanceCounter
Definition qwidget_p.h:701
uint inheritedFontResolveMask
Definition qwidget_p.h:690
QWidget * focus_next
Definition qwidget_p.h:648
QWidgetData data
Definition qwidget_p.h:704
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
Definition qwidget_p.h:712
bool isOverlapped(const QRect &rect) const
Definition qwidget_p.h:359
QRect mapFromWS(const QRect &r) const
Definition qwidget_p.h:585
QList< QAction * > actions
Definition qwidget_p.h:709
void createTLExtra()
Definition qwidget.cpp:1599
uint usesDoubleBufferedGLContext
Definition qwidget_p.h:725
virtual bool isStereoEnabled()
Definition qwidget_p.h:636
uint childrenHiddenByWState
Definition qwidget_p.h:734
signed char leftLayoutItemMargin
Definition qwidget_p.h:697
virtual void beginBackingStorePainting()
Definition qwidget_p.h:606
uint childrenShownByExpose
Definition qwidget_p.h:735
QPalette::ResolveMask inheritedPaletteResolveMask
Definition qwidget_p.h:692
virtual QImage grabFramebuffer()
Definition qwidget_p.h:605
uint renderToTextureReallyDirty
Definition qwidget_p.h:732
virtual void endBackingStorePainting()
Definition qwidget_p.h:607
virtual QPlatformBackingStoreRhiConfig rhiConfig() const
Definition qwidget_p.h:590
QRect effectiveRectFor(const QRect &rect) const
Definition qwidget_p.h:545
QPaintDevice * redirectDev
Definition qwidget_p.h:653
static QWidgetMapper * mapper
Definition qwidget_p.h:661
void restoreRedirected()
Definition qwidget_p.h:517
void setSharedPainter(QPainter *painter)
Definition qwidget_p.h:879
uint retainSizeWhenHiddenChanged
Definition qwidget_p.h:721
QPalette::ColorRole bg_role
Definition qwidget_p.h:718
static QWidgetPrivate * get(QWidget *w)
Definition qwidget_p.h:212
uint inheritsInputMethodHints
Definition qwidget_p.h:730
signed char topLayoutItemMargin
Definition qwidget_p.h:698
QPoint mapFromWS(const QPoint &p) const
Definition qwidget_p.h:579
QPoint mapToWS(const QPoint &p) const
Definition qwidget_p.h:576
QWidgetRepaintManager * maybeRepaintManager() const
Definition qwidget_p.h:893
short bottommargin
Definition qwidget_p.h:696
void handleSoftwareInputPanel(bool clickCausedFocus=false)
Definition qwidget_p.h:562
virtual void aboutToDestroy()
Definition qwidget_p.h:438
QPaintEngine * extraPaintEngine
Definition qwidget_p.h:655
static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition=true)
Definition qwidget_p.h:493
std::unique_ptr< QWExtra > extra
Definition qwidget_p.h:647
bool nativeChildrenForced() const
Definition qwidget_p.h:535
QRect mapToWS(const QRect &r) const
Definition qwidget_p.h:582
virtual void resizeViewportFramebuffer()
Definition qwidget_p.h:630
void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
Definition qwidget_p.h:556
signed char bottomLayoutItemMargin
Definition qwidget_p.h:700
QRegion dirty
Definition qwidget_p.h:672
QLocale locale
Definition qwidget_p.h:706
QGraphicsEffect * graphicsEffect
Definition qwidget_p.h:657
signed char rightLayoutItemMargin
Definition qwidget_p.h:699
uint textureChildSeen
Definition qwidget_p.h:728
void setRedirected(QPaintDevice *replacement, const QPoint &offset)
Definition qwidget_p.h:503
static QRect availableScreenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition=true)
Definition qwidget_p.h:498
bool insertIntoFocusChainAfter(QWidget *position)
Definition qwidget_p.h:759
static QWidget * parentGraphicsView(const QWidget *widget)
Definition qwidget_p.h:451
QWidget * focus_child
Definition qwidget_p.h:650
QPalette::ColorRole fg_role
Definition qwidget_p.h:717
virtual void beginCompose()
Definition qwidget_p.h:608
QRegion opaqueChildren
Definition qwidget_p.h:671
bool insertIntoFocusChainBefore(QWidget *position)
Definition qwidget_p.h:757
bool pointInsideRectAndMask(const QPoint &) const
Definition qwidget_p.h:886
Qt::HANDLE hd
Definition qwidget_p.h:703
QWidgetItemV2 * widgetItem
Definition qwidget_p.h:654
short rightmargin
Definition qwidget_p.h:695
virtual void resolveSamples()
Definition qwidget_p.h:632
void enforceNativeChildren()
Definition qwidget_p.h:520
QWExtra * extraData() const
Definition qwidget_p.h:856
void setRenderToTexture()
Definition qwidget_p.h:610
static QRect screenGeometry(const QWidget *widget)
Definition qwidget_p.h:469
uint renderToTexture
Definition qwidget_p.h:727
QRect effectiveRectFor(const QRegion &region) const
Definition qwidget_p.h:540
QWidget * focus_prev
Definition qwidget_p.h:649
virtual void initializeViewportFramebuffer()
Definition qwidget_p.h:626
QSizePolicy size_policy
Definition qwidget_p.h:705
QWidget * effectiveFocusWidget()
Definition qwidget_p.h:440
static QScreen * screen(const QWidget *widget, const QPoint &globalPosition, bool hasPosition=true)
Definition qwidget_p.h:479
QTLWExtra * topData() const
Definition qwidget_p.h:861
QPoint redirectOffset
Definition qwidget_p.h:707
QPaintDevice * redirected(QPoint *offset) const
Definition qwidget_p.h:510
QPainter * sharedPainter() const
Definition qwidget_p.h:872
virtual bool toggleStereoTargetBuffer()
Definition qwidget_p.h:637
uint directFontResolveMask
Definition qwidget_p.h:689
virtual QPlatformTextureList::Flags textureListFlags()
Definition qwidget_p.h:599
Qt::InputMethodHints imHints
Definition qwidget_p.h:664
void setFont_helper(const QFont &font)
Definition qwidget_p.h:276
static int maxInstances
Definition qwidget_p.h:702
virtual TextureData texture() const
Definition qwidget_p.h:598
static QRect availableScreenGeometry(const QWidget *widget)
Definition qwidget_p.h:474
void setTextureChildSeen()
Definition qwidget_p.h:611
virtual void endCompose()
Definition qwidget_p.h:609
QLayout * layout
Definition qwidget_p.h:651
static QWidgetSet * allWidgets
Definition qwidget_p.h:662
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QScreen * screen() const
Returns the screen the widget is on.
Definition qwidget.cpp:2496
\inmodule QtGui
Definition qwindow.h:63
QOpenGLWidget * widget
[1]
QPushButton * button
[2]
QCursor cursor
rect
[4]
direction
QStyleOptionButton opt
Combined button and popup list for selecting options.
MouseButton
Definition qnamespace.h:56
@ LeftButton
Definition qnamespace.h:58
@ WA_AlwaysStackOnTop
Definition qnamespace.h:411
@ WA_NativeWindow
Definition qnamespace.h:378
@ WA_WState_InPaintEvent
Definition qnamespace.h:329
@ WA_MouseNoMask
Definition qnamespace.h:338
LayoutDirection
FocusPolicy
Definition qnamespace.h:106
Orientation
Definition qnamespace.h:98
void * HANDLE
CoordinateSystem
@ BypassGraphicsProxyWidget
Definition qnamespace.h:243
ShortcutContext
Definition brush.cpp:5
static void * context
#define qApp
static QDBusError::ErrorType get(const char *name)
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
#define Q_DECLARE_LOGGING_CATEGORY(name)
static void setLayoutItemMargins(int left, int top, int right, int bottom, QRect *rect, Qt::LayoutDirection dir)
@ QObjectPrivateVersion
Definition qobject_p.h:61
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLuint index
[2]
GLboolean r
[2]
GLuint GLuint end
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLint left
GLint GLint bottom
GLenum target
GLbitfield flags
GLenum GLuint GLintptr offset
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
GLenum cap
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
void forceUpdate(QQuickItem *item)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QScreen * screen
[1]
Definition main.cpp:29
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define Q_ENUM(x)
#define Q_FLAG(x)
#define Q_GADGET
#define Q_UNUSED(x)
unsigned short quint16
Definition qtypes.h:48
int qint32
Definition qtypes.h:49
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType)
static bool bypassGraphicsProxyWidget(const QWidget *p)
Definition qwidget_p.h:169
QT_BEGIN_NAMESPACE typedef QHash< WId, QWidget * > QWidgetMapper
Definition qwindowdefs.h:68
QObject::connect nullptr
QLayoutItem * child
[0]
widget render & pixmap
QPainter painter(this)
[7]
myWidget render(this)
QSizePolicy policy
QQuickView * view
[0]
view create()
\inmodule QtCore
QRect frameStrut
Definition qwidget_p.h:109
QString role
Definition qwidget_p.h:102
QString iconText
Definition qwidget_p.h:101
QString caption
Definition qwidget_p.h:100
std::unique_ptr< QWidgetRepaintManager > repaintManager
Definition qwidget_p.h:94
uint posIncludesFrame
Definition qwidget_p.h:118
QRect normalGeometry
Definition qwidget_p.h:110
Qt::WindowFlags savedFlags
Definition qwidget_p.h:111
QPainter * sharedPainter
Definition qwidget_p.h:96
std::unique_ptr< QIcon > icon
Definition qwidget_p.h:93
uint opacity
Definition qwidget_p.h:117
std::vector< std::unique_ptr< QPlatformTextureList > > widgetTextures
Definition qwidget_p.h:114
uint sizeAdjusted
Definition qwidget_p.h:119
short baseh
Definition qwidget_p.h:107
QScreen * initialScreen
Definition qwidget_p.h:112
QBackingStore * backingStore
Definition qwidget_p.h:95
QString filePath
Definition qwidget_p.h:103
short inch
Definition qwidget_p.h:106
short basew
Definition qwidget_p.h:107
QWidgetWindow * window
Definition qwidget_p.h:97
uint embedded
Definition qwidget_p.h:120
short incw
Definition qwidget_p.h:106
uint hasMask
Definition qwidget_p.h:157
uint hasWindowContainer
Definition qwidget_p.h:158
QString styleSheet
Definition qwidget_p.h:140
QRegion mask
Definition qwidget_p.h:139
qint32 minw
Definition qwidget_p.h:143
QSize staticContentsSize
Definition qwidget_p.h:149
QPointer< QWidget > focus_proxy
Definition qwidget_p.h:136
uint inRenderWithPainter
Definition qwidget_p.h:156
qint32 maxh
Definition qwidget_p.h:146
quint16 customDpiY
Definition qwidget_p.h:148
uint nativeChildrenForced
Definition qwidget_p.h:155
quint16 customDpiX
Definition qwidget_p.h:147
std::unique_ptr< QTLWExtra > topextra
Definition qwidget_p.h:128
void * glContext
Definition qwidget_p.h:127
std::unique_ptr< QCursor > curs
Definition qwidget_p.h:133
uint explicitMinSize
Definition qwidget_p.h:152
uint autoFillBackground
Definition qwidget_p.h:154
QPointer< QStyle > style
Definition qwidget_p.h:135
uint explicitMaxSize
Definition qwidget_p.h:153
qint32 maxw
Definition qwidget_p.h:145
qint32 minh
Definition qwidget_p.h:144
QWidgetRepaintManager * repaintManager
Definition qwidget_p.h:797
QPainter * painter
Definition qwidget_p.h:798
QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f, QPainter *p, QWidgetRepaintManager *rpm)
Definition qwidget_p.h:788
QPaintDevice * pdev
Definition qwidget_p.h:792
QWidgetPrivate::DrawWidgetFlags flags
Definition qwidget_p.h:795
QPainter * sharedPainter
Definition qwidget_p.h:796