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
qqstylekitcustomcontrol.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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
5
7
8/*!
9 \qmltype CustomControl
10 \inqmlmodule Qt.labs.StyleKit
11 \inherits ControlStyle
12 \brief Defines styling for a custom (non-built-in) control.
13
14 CustomControl allows you to define and style controls that are not part of
15 \l {Qt Quick Controls}. This is convenient if you have additional controls
16 or components that should be styled according to the active \l Style and \l Theme.
17
18 Like the built-in control types (such as
19 \l {AbstractStylableControls::}{abstractButton},
20 \l {AbstractStylableControls::}{pane}, and
21 \l {AbstractStylableControls::}{slider}), CustomControl inherits
22 \l ControlStyle. Unlike built-in types, which are implicitly connected to
23 their control type, a CustomControl requires \l controlType to be set
24 explicitly. Apart from that, they work exactly the same way.
25
26 A \l Style or \l Theme can define as many custom controls as needed, and a
27 CustomControl in a Theme can have the same \l controlType as one in the \l Style.
28 That is no different from, for example, a \l {AbstractStylableControls::}{slider}
29 being styled by both the \l Style and the \l Theme. The fallback logic is the same.
30
31 Any style properties not set on a CustomControl fall back to those set
32 on a \l {AbstractStylableControls::}{control}.
33
34 The following snippet shows how to define styling for a custom control:
35
36 \snippet CustomControlSnippets.qml custom control style
37
38 And the following snippet shows an example on how to implement a custom
39 control that uses it:
40
41 \snippet CustomControlSnippets.qml custom control
42
43 \labs
44
45 \sa StyleReader, ControlStyle, Style
46*/
47
48/*!
49 \qmlproperty int CustomControl::controlType
50
51 A unique integer identifying this custom control type. Set the same value
52 on the \l {StyleReader::controlType}{StyleReader.controlType} in your
53 custom control implementation to connect it to this style definition.
54
55 Custom control types must be in the range \c 0 to \c 100000.
56
57 \sa {StyleReader::controlType}{StyleReader.controlType}
58*/
59
60using namespace Qt::StringLiterals;
61
62QQStyleKitCustomControl::QQStyleKitCustomControl(QObject *parent)
63 : QQStyleKitControl(parent)
64{
65}
66
68{
69 return m_controlType;
70}
71
73{
74 if (m_controlType == controlType)
75 return;
76
77 m_controlType = controlType;
78
79 emit controlTypeChanged();
80}
81
82QT_END_NAMESPACE
83
84#include "moc_qqstylekitcustomcontrol_p.cpp"
void setControlType(int controlType)
Combined button and popup list for selecting options.