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
qquickstyle.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// Qt-Security score:significant reason:default
4
5#ifndef QSTYLE_H
6#define QSTYLE_H
7
8#include <QtCore/qobject.h>
9#include <QtCore/qrect.h>
10#include <QtCore/qsize.h>
11#include <QtGui/qwindow.h>
12#include <QtGui/qicon.h>
13#include <QtGui/qpixmap.h>
14#include <QtGui/qpalette.h>
15
16QT_BEGIN_NAMESPACE
17
18class QAction;
19class QDebug;
20class QFontMetrics;
21
22namespace QQC2 {
23
25class QStyleOption;
27class QStylePrivate;
28
29class QStyle : public QObject
30{
31 Q_OBJECT
32 Q_DECLARE_PRIVATE(QStyle)
33
34protected:
36
37public:
38 QStyle();
39 virtual ~QStyle();
40
41 enum StateFlag {
42 State_None = 0x00000000,
43 State_Enabled = 0x00000001,
44 State_Raised = 0x00000002,
45 State_Sunken = 0x00000004,
46 State_Off = 0x00000008,
47 State_NoChange = 0x00000010,
48 State_On = 0x00000020,
49 State_DownArrow = 0x00000040,
50 State_Horizontal = 0x00000080,
51 State_HasFocus = 0x00000100,
52 State_Top = 0x00000200,
53 State_Bottom = 0x00000400,
54 State_FocusAtBorder = 0x00000800,
55 State_AutoRaise = 0x00001000,
56 State_MouseOver = 0x00002000,
57 State_UpArrow = 0x00004000,
58 State_Selected = 0x00008000,
59 State_Active = 0x00010000,
60 State_Window = 0x00020000,
61 State_Open = 0x00040000,
62 State_Children = 0x00080000,
63 State_Item = 0x00100000,
64 State_Sibling = 0x00200000,
65 State_Editing = 0x00400000,
67#ifdef QT_KEYPAD_NAVIGATION
68 State_HasEditFocus = 0x01000000,
69#endif
70 State_ReadOnly = 0x02000000,
71 State_Small = 0x04000000,
72 State_Mini = 0x08000000
73 };
76
141 Q_ENUM(PrimitiveElement)
142
210 Q_ENUM(ControlElement)
211
215
220
225
227
229
233
235
238
244
248
250
253
258
271
275
279
283
285
287
291
292 // do not add any values below/greater than this
293 SE_CustomBase = 0xf0000000
294 };
295 Q_ENUM(SubElement)
296
312 Q_ENUM(ComplexControl)
313
315 SC_None = 0x00000000,
316
321 SC_ScrollBarFirst = 0x00000010,
322 SC_ScrollBarLast = 0x00000020,
323 SC_ScrollBarSlider = 0x00000040,
324 SC_ScrollBarGroove = 0x00000080,
325
326 SC_SpinBoxUp = 0x00000001,
327 SC_SpinBoxDown = 0x00000002,
328 SC_SpinBoxFrame = 0x00000004,
330
331 SC_ComboBoxFrame = 0x00000001,
333 SC_ComboBoxArrow = 0x00000004,
335
341
342 SC_SliderGroove = 0x00000001,
343 SC_SliderHandle = 0x00000002,
344 SC_SliderTickmarks = 0x00000004,
345
346 SC_ToolButton = 0x00000001,
347 SC_ToolButtonMenu = 0x00000002,
348
349 SC_TitleBarSysMenu = 0x00000001,
357 SC_TitleBarLabel = 0x00000100,
358
359 SC_DialGroove = 0x00000001,
360 SC_DialHandle = 0x00000002,
361 SC_DialTickmarks = 0x00000004,
362
364 SC_GroupBoxLabel = 0x00000002,
366 SC_GroupBoxFrame = 0x00000008,
367
368 SC_MdiMinButton = 0x00000001,
369 SC_MdiNormalButton = 0x00000002,
370 SC_MdiCloseButton = 0x00000004,
371
372 SC_CustomBase = 0xf0000000,
373 SC_All = 0xffffffff
374 };
375 Q_ENUM(SubControl)
377
384
389
391
394
395 PM_SliderThickness, // total slider thickness
396 PM_SliderControlThickness, // thickness of the business part
397 PM_SliderLength, // total length of slider
399 PM_SliderSpaceAvailable, // available space for slider to move
400
404
410
412
415
422
427
432
436
439
446
453
455
459
465
468
476
478
487
489
492
497
500
503
514
515 // do not add any values below/greater than this
516 PM_CustomBase = 0xf0000000
517 };
518 Q_ENUM(PixelMetric)
519
550 Q_ENUM(ContentsType)
551
556 Q_ENUM(RequestSoftwareInputPanel)
557
662 // Whether we should use a native popup.
663 // Only supported for non-editable combo boxes on Mac OS X so far.
679 // Add new style hint values here
680
681 SH_CustomBase = 0xf0000000
682 };
683 Q_ENUM(StyleHint)
684
764 // do not add any values below/greater than this
765 SP_CustomBase = 0xf0000000
766 };
767 Q_ENUM(StandardPixmap)
768
769 virtual QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const;
770 virtual QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const;
771 virtual QRect subElementRect(SubElement subElement, const QStyleOption *option) const = 0;
772 virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc) const = 0;
773
774 virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize) const = 0;
775 virtual QFont font(ControlElement element, const QStyle::State state) const = 0;
776 virtual QMargins ninePatchMargins(ControlElement ce, const QStyleOption *opt, const QSize &imageSize) const = 0;
777 virtual QMargins ninePatchMargins(ComplexControl cc, const QStyleOptionComplex *opt, const QSize &imageSize) const = 0;
778
779 virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt) const = 0;
780
781 virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr) const = 0;
782 virtual int styleHint(StyleHint stylehint, const QStyleOption *opt = nullptr, QStyleHintReturn* returnData = nullptr) const = 0;
783
784 virtual void drawItemText(QPainter *painter, const QRect &rect,
785 int flags, const QPalette &pal, bool enabled,
786 const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const;
787 virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const;
788 virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p) const = 0;
789 virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p) const = 0;
790 virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p) const = 0;
791
792 virtual QPalette standardPalette() const;
793 virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt = nullptr) const = 0;
794 virtual QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option = nullptr) const = 0;
795 virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const = 0;
796 virtual void polish() { }
797
798 static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect);
799 static QPoint visualPos(Qt::LayoutDirection direction, const QRect &boundingRect, const QPoint &logicalPos);
800 static int sliderPositionFromValue(int min, int max, int val, int space, bool upsideDown = false);
801 static int sliderValueFromPosition(int min, int max, int pos, int space, bool upsideDown = false);
802 static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment);
803 static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle);
804
805 // TODO: Remove the concept of proxy (but keep it for now until everything builds)
806 const QStyle *proxy() const { return this; }
807
808 virtual void handleThemeChange() {}
809
810private:
812};
813
814Q_DECLARE_OPERATORS_FOR_FLAGS(QStyle::State)
816
817} // namespace QQC2
818
819QT_END_NAMESPACE
820
821#endif // QSTYLE_H
virtual void polish()
const QStyle * proxy() const
virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt=nullptr) const =0
virtual QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
Returns the area within the given rectangle in which to draw the specified pixmap according to the de...
virtual QPalette standardPalette() const
Returns the style's standard palette.
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize) const =0
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr) const =0
virtual void handleThemeChange()
virtual ~QStyle()
Destroys the style object.
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment,...
virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p) const =0
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p) const =0
virtual QFont font(ControlElement element, const QStyle::State state) const =0
QStyle()
Constructs a style object.
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p) const =0
static int sliderPositionFromValue(int min, int max, int val, int space, bool upsideDown=false)
Converts the given logicalValue to a pixel position.
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc) const =0
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction.
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option) const =0
static int sliderValueFromPosition(int min, int max, int pos, int space, bool upsideDown=false)
Converts the given pixel position to a logical value.
virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const =0
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, QStyleHintReturn *returnData=nullptr) const =0
@ State_KeyboardFocusChange
Definition qquickstyle.h:66
virtual QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr) const =0
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.
virtual QMargins ninePatchMargins(ComplexControl cc, const QStyleOptionComplex *opt, const QSize &imageSize) const =0
virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt) const =0
virtual QMargins ninePatchMargins(ControlElement ce, const QStyleOption *opt, const QSize &imageSize) const =0
static QPoint visualPos(Qt::LayoutDirection direction, const QRect &boundingRect, const QPoint &logicalPos)
Returns the given logicalPosition converted to screen coordinates based on the specified direction.