QtBase  v6.3.1
qgraphicswidget.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QGRAPHICSWIDGET_H
41 #define QGRAPHICSWIDGET_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtGui/qfont.h>
45 #if QT_CONFIG(action)
46 # include <QtGui/qaction.h>
47 #endif
48 #include <QtWidgets/qgraphicslayoutitem.h>
49 #include <QtWidgets/qgraphicsitem.h>
50 #include <QtGui/qpalette.h>
51 
52 QT_REQUIRE_CONFIG(graphicsview);
53 
55 
56 class QFont;
57 class QFontMetrics;
58 class QGraphicsLayout;
62 class QStyle;
63 class QStyleOption;
64 
66 
67 class Q_WIDGETS_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLayoutItem
68 {
69  Q_OBJECT
71  Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
72  Q_PROPERTY(QFont font READ font WRITE setFont)
73  Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection
74  RESET unsetLayoutDirection)
75  Q_PROPERTY(QSizeF size READ size WRITE resize NOTIFY geometryChanged)
76  Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize)
77  Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize)
78  Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize)
80  Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
81  Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
82  Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
83  Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
84  Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
85  Q_PROPERTY(QGraphicsLayout* layout READ layout WRITE setLayout NOTIFY layoutChanged)
86 public:
87  QGraphicsWidget(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = Qt::WindowFlags());
88  ~QGraphicsWidget();
89  QGraphicsLayout *layout() const;
91  void adjustSize();
92 
93  Qt::LayoutDirection layoutDirection() const;
94  void setLayoutDirection(Qt::LayoutDirection direction);
95  void unsetLayoutDirection();
96 
97  QStyle *style() const;
98  void setStyle(QStyle *style);
99 
100  QFont font() const;
101  void setFont(const QFont &font);
102 
103  QPalette palette() const;
104  void setPalette(const QPalette &palette);
105 
106  bool autoFillBackground() const;
107  void setAutoFillBackground(bool enabled);
108 
109  void resize(const QSizeF &size);
110  inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); }
111  QSizeF size() const;
112 
113  void setGeometry(const QRectF &rect) override;
114  inline void setGeometry(qreal x, qreal y, qreal w, qreal h);
115  inline QRectF rect() const { return QRectF(QPointF(), size()); }
116 
117  void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom);
118  void setContentsMargins(QMarginsF margins);
119  void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const override;
120 
121  void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom);
122  void setWindowFrameMargins(QMarginsF margins);
123  void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
124  void unsetWindowFrameMargins();
125  QRectF windowFrameGeometry() const;
126  QRectF windowFrameRect() const;
127 
128  // Window handling
129  Qt::WindowFlags windowFlags() const;
130  Qt::WindowType windowType() const;
131  void setWindowFlags(Qt::WindowFlags wFlags);
132  bool isActiveWindow() const;
133  void setWindowTitle(const QString &title);
134  QString windowTitle() const;
135 
136  // Focus handling
137  Qt::FocusPolicy focusPolicy() const;
138  void setFocusPolicy(Qt::FocusPolicy policy);
139  static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second);
140  QGraphicsWidget *focusWidget() const;
141 
142 #ifndef QT_NO_SHORTCUT
143  int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut);
144  void releaseShortcut(int id);
145  void setShortcutEnabled(int id, bool enabled = true);
146  void setShortcutAutoRepeat(int id, bool enabled = true);
147 #endif
148 
149 #ifndef QT_NO_ACTION
150  //actions
151  void addAction(QAction *action);
152  void addActions(const QList<QAction*> &actions);
153  void insertActions(QAction *before, const QList<QAction*> &actions);
154  void insertAction(QAction *before, QAction *action);
155  void removeAction(QAction *action);
156  QList<QAction*> actions() const;
157 #endif
158 
159  void setAttribute(Qt::WidgetAttribute attribute, bool on = true);
160  bool testAttribute(Qt::WidgetAttribute attribute) const;
161 
162  enum {
163  Type = 11
164  };
165  int type() const override;
166 
167  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
168  virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
169  QRectF boundingRect() const override;
170  QPainterPath shape() const override;
171 
172 #if 0
173  void dumpFocusChain();
174 #endif
175 
176  using QObject::children;
177 
178 Q_SIGNALS:
181 
182 public Q_SLOTS:
183  bool close();
184 
185 protected:
186  virtual void initStyleOption(QStyleOption *option) const;
187 
188  QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
189  void updateGeometry() override;
190 
191  // Notification
192  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
193  virtual QVariant propertyChange(const QString &propertyName, const QVariant &value);
194 
195  // Scene events
196  bool sceneEvent(QEvent *event) override;
197  virtual bool windowFrameEvent(QEvent *e);
198  virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF& pos) const;
199 
200  // Base event handlers
201  bool event(QEvent *event) override;
202  //virtual void actionEvent(QActionEvent *event);
203  virtual void changeEvent(QEvent *event);
204  virtual void closeEvent(QCloseEvent *event);
205  //void create(WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true);
206  //void destroy(bool destroyWindow = true, bool destroySubWindows = true);
207  void focusInEvent(QFocusEvent *event) override;
208  virtual bool focusNextPrevChild(bool next);
209  void focusOutEvent(QFocusEvent *event) override;
210  virtual void hideEvent(QHideEvent *event);
211  //virtual int metric(PaintDeviceMetric m ) const;
212  virtual void moveEvent(QGraphicsSceneMoveEvent *event);
213  virtual void polishEvent();
214  //void resetInputContext ();
215  virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
216  virtual void showEvent(QShowEvent *event);
217  //virtual void tabletEvent(QTabletEvent *event);
218  virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
219  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
220  virtual void grabMouseEvent(QEvent *event);
221  virtual void ungrabMouseEvent(QEvent *event);
222  virtual void grabKeyboardEvent(QEvent *event);
223  virtual void ungrabKeyboardEvent(QEvent *event);
224  QGraphicsWidget(QGraphicsWidgetPrivate &, QGraphicsItem *parent, Qt::WindowFlags wFlags = Qt::WindowFlags());
225 
226 private:
228  Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsWidget)
229  friend class QGraphicsScene;
230  friend class QGraphicsScenePrivate;
231  friend class QGraphicsView;
232  friend class QGraphicsItem;
233  friend class QGraphicsItemPrivate;
234  friend class QGraphicsLayout;
235  friend class QWidget;
236  friend class QApplication;
237 };
238 
239 inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
240 { setGeometry(QRectF(ax, ay, aw, ah)); }
241 
243 
244 #endif
245 
Arabic default style
Definition: afstyles.h:94
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition: qaction.h:65
The QApplication class manages the GUI application's control flow and main settings.
Definition: qapplication.h:68
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:629
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QFocusEvent class contains event parameters for widget focus events. \inmodule QtGui.
Definition: qevent.h:520
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:56
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
friend class QGraphicsWidget
QScopedPointer< QGraphicsItemPrivate > d_ptr
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
virtual QPainterPath shape() const
virtual void focusInEvent(QFocusEvent *event)
virtual QRectF boundingRect() const =0
virtual void focusOutEvent(QFocusEvent *event)
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
virtual bool sceneEvent(QEvent *event)
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const =0
virtual void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
virtual void setGeometry(const QRectF &rect)
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 QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
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 QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:60
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void layoutChanged()
QRectF rect() const
void geometryChanged()
void resize(qreal w, qreal h)
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:656
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:71
The QMarginsF class defines the four margins of a rectangle.
Definition: qmargins.h:301
const QObjectList & children() const
Definition: qobject.h:206
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:65
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:55
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:647
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition: qsizepolicy.h:54
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition: qstyle.h:65
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
Definition: qstyleoption.h:684
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:75
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QOpenGLWidget * widget
[1]
a resize(100000)
QPainter paint
double e
rect
[4]
direction
palette
short next
Definition: keywords.cpp:454
#define inline
Definition: md4c.c:45
WidgetAttribute
Definition: qnamespace.h:307
LayoutDirection
Definition: qnamespace.h:1462
FocusPolicy
Definition: qnamespace.h:131
WindowFrameSection
Definition: qnamespace.h:1597
WindowType
Definition: qnamespace.h:230
SizeHint
Definition: qnamespace.h:1589
ShortcutContext
Definition: qnamespace.h:1313
@ WindowShortcut
Definition: qnamespace.h:1315
action
Definition: devices.py:78
const char * sizePolicy(int v)
Definition: language.cpp:146
EGLOutputLayerEXT EGLint EGLAttrib value
EGLOutputLayerEXT EGLint attribute
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
QT_REQUIRE_CONFIG(graphicsview)
GLenum type
Definition: qopengl.h:270
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
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint left
GLint GLint bottom
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint first
GLint y
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
Definition: qopenglext.h:2998
GLuint GLenum option
Definition: qopenglext.h:5929
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_INTERFACES(x)
Definition: qtmetamacros.h:91
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_SIGNALS
Definition: qtmetamacros.h:81
QVBoxLayout * layout
QString title
[35]
form setLayout(layout)
setTabOrder(a, b)
[0]
app setAttribute(Qt::AA_DontShowIconsInMenus)
QPainter painter(this)
[7]
setFont(font)
widget setStyle(proxy)
QSizePolicy policy
widget setSizePolicy(policy)
Definition: moc.h:48
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent