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
styles.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page style-reference.html
6
\title Styles and Style Aware Widgets
7
\ingroup qt-gui-concepts
8
\brief How styles draw widgets, and how to customize or implement a style.
9
10
Styles (classes that inherit \l{QStyle}) draw on behalf of widgets and
11
encapsulate the look and feel of a GUI. \l QStyle is an abstract base class.
12
Qt's built-in widgets use it for nearly all of their drawing, so they look
13
exactly like the equivalent native widgets.
14
15
Qt comes with a selection of built-in styles. The \c windows and \c fusion
16
styles are part of the Qt Widgets module. The platform styles, such as
17
\c windows11 on Windows and \c macos on \macos, are plugins that are
18
available on their platform only. \l QStyleFactory lists the styles that are
19
available at runtime and creates them by name. \l QApplication::setStyle()
20
makes a style the application style, and users can select a style with the
21
\c -style command-line option.
22
23
A \l QStyle implementation is the way to give a production application its
24
own look. \l{Qt Labs StyleKit}{StyleKit} provides one, \l QStyleKitStyle,
25
that reads a QML description of the design. For when to use a style,
26
StyleKit, or a \l{Qt Style Sheets}{style sheet}, see
27
\l{Styling Approaches for Qt Widgets}.
28
29
\section1 Customizing a style
30
31
To change selected aspects of an existing style, inherit \l QProxyStyle and
32
reimplement the virtual functions that draw or measure the elements you want
33
to change. A proxy style wraps another style and forwards everything you
34
don't reimplement to it.
35
36
You can name the base style explicitly or leave it unspecified. An explicit
37
base style gives you full control and suits customizations that depend on a
38
particular style's behavior. Without a base style, the proxy wraps the
39
application style, so your customization applies on top of whatever the
40
platform provides.
41
42
\l{QStyle#Creating a Custom Style}{The QStyle class documentation} shows a
43
proxy style that replaces the arrows of a spin box.
44
45
\section1 Implementing a style
46
47
\l QCommonStyle provides a convenient base for full style implementations.
48
It implements the behavior that all of Qt's styles share, such as the layout
49
of subelements and the size calculations, and leaves the drawing to you.
50
Inherit \l QCommonStyle and reimplement the drawing functions, together with
51
the pixel metrics, subelement rectangles, and style hints that differ from
52
the common defaults. Qt's built-in styles aren't part of the public API and
53
can't serve as base classes; wrap them with \l QProxyStyle instead.
54
55
Implementing a full style is an involved task. The following pages describe
56
how the style API works, trace how a widget is drawn from its paint event to
57
the style, and list the elements, states, and options that each widget uses:
58
59
\list
60
\li \l{How a Style Draws a Widget} explains style elements, subelements,
61
pixel metrics, style hints, style options, the \l QStyle functions, and
62
the palette.
63
\li \l{Writing Style-Aware Widgets} shows how a custom widget draws through
64
the current style, so it looks right in every style.
65
\li \l{Styling a Checkbox: A Walkthrough} follows a \l QCheckBox from its
66
paint event through \l QCommonStyle and ends with a custom indicator.
67
\li \l{Widget Style Reference} lists, for each widget, the style elements it
68
draws, the state flags it sets, and the members of its style option.
69
\endlist
70
71
The elements the widgets draw are the same in every style, so you can also
72
use the reference when you write a style-aware widget or a delegate.
73
74
\section1 Classes for widget styling
75
76
Use these classes to customize an application's appearance.
77
78
\annotatedlist appearance
79
80
\sa QStyle, QProxyStyle, QCommonStyle, QStylePainter, QStyleOption,
81
{Styling Approaches for Qt Widgets}
82
*/
qtbase
src
widgets
doc
src
widgets-and-layouts
styles.qdoc
Generated on
for Qt by
1.16.1