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
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
4#ifndef QGRAPHICSWIDGET_H
5#define QGRAPHICSWIDGET_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtGui/qfont.h>
9#if QT_CONFIG(action)
10# include <QtGui/qaction.h>
11#endif
12#include <QtWidgets/qgraphicslayoutitem.h>
13#include <QtWidgets/qgraphicsitem.h>
14#include <QtGui/qpalette.h>
15
16QT_REQUIRE_CONFIG(graphicsview);
17
19
20class QFont;
21class QFontMetrics;
22class QGraphicsLayout;
26class QStyle;
27class QStyleOption;
28
30
31class Q_WIDGETS_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLayoutItem
32{
35 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
36 Q_PROPERTY(QFont font READ font WRITE setFont)
37 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
38 RESET unsetLayoutDirection)
39 Q_PROPERTY(QSizeF size READ size WRITE resize NOTIFY geometryChanged)
40 Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize)
41 Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize)
42 Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize)
43 Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
44 Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
45 Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
46 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
47 Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
48 Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
49 Q_PROPERTY(QGraphicsLayout* layout READ layout WRITE setLayout NOTIFY layoutChanged)
50public:
51 QGraphicsWidget(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = Qt::WindowFlags());
53 QGraphicsLayout *layout() const;
55 void adjustSize();
56
57 Qt::LayoutDirection layoutDirection() const;
58 void setLayoutDirection(Qt::LayoutDirection direction);
59 void unsetLayoutDirection();
60
61 QStyle *style() const;
62 void setStyle(QStyle *style);
63
64 QFont font() const;
65 void setFont(const QFont &font);
66
67 QPalette palette() const;
68 void setPalette(const QPalette &palette);
69
70 bool autoFillBackground() const;
71 void setAutoFillBackground(bool enabled);
72
73 void resize(const QSizeF &size);
74 inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); }
75 QSizeF size() const;
76
77 void setGeometry(const QRectF &rect) override;
78 inline void setGeometry(qreal x, qreal y, qreal w, qreal h);
79 inline QRectF rect() const { return QRectF(QPointF(), size()); }
80
81 void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom);
82 void setContentsMargins(QMarginsF margins);
83 void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const override;
84
85 void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom);
86 void setWindowFrameMargins(QMarginsF margins);
87 void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
88 void unsetWindowFrameMargins();
89 QRectF windowFrameGeometry() const;
90 QRectF windowFrameRect() const;
91
92 // Window handling
93 Qt::WindowFlags windowFlags() const;
94 Qt::WindowType windowType() const;
95 void setWindowFlags(Qt::WindowFlags wFlags);
96 bool isActiveWindow() const;
97 void setWindowTitle(const QString &title);
98 QString windowTitle() const;
99
100 // Focus handling
101 Qt::FocusPolicy focusPolicy() const;
102 void setFocusPolicy(Qt::FocusPolicy policy);
103 static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second);
104 QGraphicsWidget *focusWidget() const;
105
106#ifndef QT_NO_SHORTCUT
107 int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut);
108 void releaseShortcut(int id);
109 void setShortcutEnabled(int id, bool enabled = true);
110 void setShortcutAutoRepeat(int id, bool enabled = true);
111#endif
112
113#ifndef QT_NO_ACTION
114 //actions
115 void addAction(QAction *action);
116 void addActions(const QList<QAction*> &actions);
117 void insertActions(QAction *before, const QList<QAction*> &actions);
118 void insertAction(QAction *before, QAction *action);
119 void removeAction(QAction *action);
120 QList<QAction*> actions() const;
121#endif
122
123 void setAttribute(Qt::WidgetAttribute attribute, bool on = true);
124 bool testAttribute(Qt::WidgetAttribute attribute) const;
125
126 enum {
127 Type = 11
128 };
129 int type() const override;
130
131 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
132 virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
133 QRectF boundingRect() const override;
134 QPainterPath shape() const override;
135
136#if 0
137 void dumpFocusChain();
138#endif
139
140 using QObject::children;
141
145
146public Q_SLOTS:
147 bool close();
148
149protected:
150 virtual void initStyleOption(QStyleOption *option) const;
151
152 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
153 void updateGeometry() override;
154
155 // Notification
156 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
157 virtual QVariant propertyChange(const QString &propertyName, const QVariant &value);
158
159 // Scene events
160 bool sceneEvent(QEvent *event) override;
161 virtual bool windowFrameEvent(QEvent *e);
162 virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF& pos) const;
163
164 // Base event handlers
165 bool event(QEvent *event) override;
166 //virtual void actionEvent(QActionEvent *event);
167 virtual void changeEvent(QEvent *event);
168 virtual void closeEvent(QCloseEvent *event);
169 //void create(WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true);
170 //void destroy(bool destroyWindow = true, bool destroySubWindows = true);
171 void focusInEvent(QFocusEvent *event) override;
172 virtual bool focusNextPrevChild(bool next);
173 void focusOutEvent(QFocusEvent *event) override;
174 virtual void hideEvent(QHideEvent *event);
175 //virtual int metric(PaintDeviceMetric m ) const;
176 virtual void moveEvent(QGraphicsSceneMoveEvent *event);
177 virtual void polishEvent();
178 //void resetInputContext ();
179 virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
180 virtual void showEvent(QShowEvent *event);
181 //virtual void tabletEvent(QTabletEvent *event);
182 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
183 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
184 virtual void grabMouseEvent(QEvent *event);
185 virtual void ungrabMouseEvent(QEvent *event);
186 virtual void grabKeyboardEvent(QEvent *event);
187 virtual void ungrabKeyboardEvent(QEvent *event);
188 QGraphicsWidget(QGraphicsWidgetPrivate &, QGraphicsItem *parent, Qt::WindowFlags wFlags = Qt::WindowFlags());
189
190private:
191 Q_DISABLE_COPY(QGraphicsWidget)
192 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsWidget)
193 friend class QGraphicsScene;
195 friend class QGraphicsView;
196 friend class QGraphicsItem;
198 friend class QGraphicsLayout;
199 friend class QWidget;
200 friend class QApplication;
201};
202
203inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
204{ setGeometry(QRectF(ax, ay, aw, ah)); }
205
207
208#endif
209
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
The QApplication class manages the GUI application's control flow and main settings.
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:562
\inmodule QtCore
Definition qcoreevent.h:45
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:22
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
QScopedPointer< QGraphicsItemPrivate > d_ptr
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
The QGraphicsObject class provides a base class for all graphics items that require signals,...
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
The QGraphicsSceneMoveEvent class provides events for widget moving in the graphics view framework.
The QGraphicsSceneResizeEvent class provides events for widget resizing in the graphics view framewor...
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void layoutChanged()
This signal gets emitted whenever the layout of the item changes.
QRectF rect() const
Returns the item's local rect as a QRectF.
void geometryChanged()
This signal gets emitted whenever the geometry is changed in setGeometry().
void resize(qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
The QKeySequence class encapsulates a key sequence as used by shortcuts.
\inmodule QtCore
Definition qmargins.h:270
const QObjectList & children() const
Returns a list of child objects.
Definition qobject.h:201
\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
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qrect.h:484
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
\inmodule QtCore
Definition qsize.h:208
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
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
\inmodule QtCore
Definition qvariant.h:65
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
a resize(100000)
QPainter paint
rect
[4]
direction
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition qcompare.h:63
WidgetAttribute
Definition qnamespace.h:282
FocusPolicy
Definition qnamespace.h:106
WindowFrameSection
WindowType
Definition qnamespace.h:205
ShortcutContext
@ WindowShortcut
static void * context
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputLayerEXT EGLint attribute
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint left
GLenum type
GLint GLint bottom
GLint first
GLint y
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
GLuint GLenum option
static const QRectF boundingRect(const QPointF *points, int pointCount)
#define QT_REQUIRE_CONFIG(feature)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INTERFACES(x)
#define Q_SLOTS
#define Q_SIGNALS
double qreal
Definition qtypes.h:187
static QString windowTitle(HWND hwnd)
QVBoxLayout * layout
QString title
[35]
setTabOrder(a, b)
[0]
app setAttribute(Qt::AA_DontShowIconsInMenus)
QPainter painter(this)
[7]
widget setStyle(proxy)
groupBox setLayout(vbox)
QSizePolicy policy
widget setSizePolicy(policy)
Definition moc.h:23