Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgraphicswidget.h
Go to the documentation of this file.
1// Copyright (C) 2016 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// Qt-Security score:significant reason:default
4
5#ifndef QGRAPHICSWIDGET_H
6#define QGRAPHICSWIDGET_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtGui/qfont.h>
10#if QT_CONFIG(action)
11# include <QtGui/qaction.h>
12#endif
13#include <QtWidgets/qgraphicslayoutitem.h>
14#include <QtWidgets/qgraphicsitem.h>
15#include <QtGui/qpalette.h>
16
18
19QT_BEGIN_NAMESPACE
20
21class QFont;
22class QFontMetrics;
23class QGraphicsLayout;
24class QGraphicsSceneMoveEvent;
26class QGraphicsSceneResizeEvent;
27class QStyle;
28class QStyleOption;
29
31
32class Q_WIDGETS_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLayoutItem
33{
34 Q_OBJECT
35 Q_INTERFACES(QGraphicsItem QGraphicsLayoutItem)
36 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
37 Q_PROPERTY(QFont font READ font WRITE setFont)
38 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
39 RESET unsetLayoutDirection)
40 Q_PROPERTY(QSizeF size READ size WRITE resize NOTIFY geometryChanged)
41 Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize)
42 Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize)
43 Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize)
44 Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
45 Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
46 Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
47 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
48 Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
49 Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
50 Q_PROPERTY(QGraphicsLayout* layout READ layout WRITE setLayout NOTIFY layoutChanged)
51public:
52 QGraphicsWidget(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = Qt::WindowFlags());
53 ~QGraphicsWidget();
54 QGraphicsLayout *layout() const;
55 void setLayout(QGraphicsLayout *layout);
56 void adjustSize();
57
58 Qt::LayoutDirection layoutDirection() const;
59 void setLayoutDirection(Qt::LayoutDirection direction);
60 void unsetLayoutDirection();
61
62 QStyle *style() const;
63 void setStyle(QStyle *style);
64
65 QFont font() const;
66 void setFont(const QFont &font);
67
68 QPalette palette() const;
69 void setPalette(const QPalette &palette);
70
71 bool autoFillBackground() const;
72 void setAutoFillBackground(bool enabled);
73
74 void resize(const QSizeF &size);
75 inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); }
76 QSizeF size() const;
77
78 void setGeometry(const QRectF &rect) override;
79 inline void setGeometry(qreal x, qreal y, qreal w, qreal h);
80 inline QRectF rect() const { return QRectF(QPointF(), size()); }
81
82 void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom);
83 void setContentsMargins(QMarginsF margins);
84 void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const override;
85
86 void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom);
87 void setWindowFrameMargins(QMarginsF margins);
88 void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
89 void unsetWindowFrameMargins();
90 QRectF windowFrameGeometry() const;
91 QRectF windowFrameRect() const;
92
93 // Window handling
94 Qt::WindowFlags windowFlags() const;
95 Qt::WindowType windowType() const;
96 void setWindowFlags(Qt::WindowFlags wFlags);
97 bool isActiveWindow() const;
98 void setWindowTitle(const QString &title);
99 QString windowTitle() const;
100
101 // Focus handling
102 Qt::FocusPolicy focusPolicy() const;
103 void setFocusPolicy(Qt::FocusPolicy policy);
104 static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second);
105 QGraphicsWidget *focusWidget() const;
106
107#ifndef QT_NO_SHORTCUT
108 int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut);
109 void releaseShortcut(int id);
110 void setShortcutEnabled(int id, bool enabled = true);
111 void setShortcutAutoRepeat(int id, bool enabled = true);
112#endif
113
114#ifndef QT_NO_ACTION
115 //actions
116 void addAction(QAction *action);
117 void addActions(const QList<QAction*> &actions);
118 void insertActions(QAction *before, const QList<QAction*> &actions);
119 void insertAction(QAction *before, QAction *action);
120 void removeAction(QAction *action);
121 QList<QAction*> actions() const;
122#endif
123
124 void setAttribute(Qt::WidgetAttribute attribute, bool on = true);
125 bool testAttribute(Qt::WidgetAttribute attribute) const;
126
127 enum {
128 Type = 11
129 };
130 int type() const override;
131
132 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
133 virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
134 QRectF boundingRect() const override;
135 QPainterPath shape() const override;
136
137#if 0
138 void dumpFocusChain();
139#endif
140
141 using QObject::children;
142
143Q_SIGNALS:
144 void geometryChanged();
145 void layoutChanged();
146
147public Q_SLOTS:
148 bool close();
149
150protected:
151 virtual void initStyleOption(QStyleOption *option) const;
152
153 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
154 void updateGeometry() override;
155
156 // Notification
157 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
158 virtual QVariant propertyChange(const QString &propertyName, const QVariant &value);
159
160 // Scene events
161 bool sceneEvent(QEvent *event) override;
162 virtual bool windowFrameEvent(QEvent *e);
163 virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF& pos) const;
164
165 // Base event handlers
166 bool event(QEvent *event) override;
167 //virtual void actionEvent(QActionEvent *event);
168 virtual void changeEvent(QEvent *event);
169 virtual void closeEvent(QCloseEvent *event);
170 //void create(WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true);
171 //void destroy(bool destroyWindow = true, bool destroySubWindows = true);
172 void focusInEvent(QFocusEvent *event) override;
173 virtual bool focusNextPrevChild(bool next);
174 void focusOutEvent(QFocusEvent *event) override;
175 virtual void hideEvent(QHideEvent *event);
176 //virtual int metric(PaintDeviceMetric m ) const;
177 virtual void moveEvent(QGraphicsSceneMoveEvent *event);
178 virtual void polishEvent();
179 //void resetInputContext ();
180 virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
181 virtual void showEvent(QShowEvent *event);
182 //virtual void tabletEvent(QTabletEvent *event);
183 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
184 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
185 virtual void grabMouseEvent(QEvent *event);
186 virtual void ungrabMouseEvent(QEvent *event);
187 virtual void grabKeyboardEvent(QEvent *event);
188 virtual void ungrabKeyboardEvent(QEvent *event);
189 QGraphicsWidget(QGraphicsWidgetPrivate &, QGraphicsItem *parent, Qt::WindowFlags wFlags = Qt::WindowFlags());
190
191private:
192 Q_DISABLE_COPY(QGraphicsWidget)
193 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsWidget)
194 friend class QGraphicsScene;
195 friend class QGraphicsScenePrivate;
196 friend class QGraphicsView;
197 friend class QGraphicsItem;
198 friend class QGraphicsItemPrivate;
199 friend class QGraphicsLayout;
200 friend class QWidget;
201 friend class QApplication;
202};
203
204inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
205{ setGeometry(QRectF(ax, ay, aw, ah)); }
206
207QT_END_NAMESPACE
208
209#endif
QGraphicsGridLayoutEngine engine
QGraphicsLayoutStyleInfo * styleInfo() const
QScopedPointer< QGraphicsLayoutStyleInfo > m_styleInfo
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View.
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
QT_REQUIRE_CONFIG(thread)