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
qqstylekitcontrols.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
7
9
10/*!
11 \qmltype StylableControls
12 \nativetype QQStyleKitControls
13 \inqmlmodule Qt.labs.StyleKit
14 \brief Abstract base type containing the control types that can be styled.
15
16 StylableControls is an abstract base type. It contains a \l ControlStyle for
17 each control type that can be styled by a \l Style, \l Theme, or \l StyleVariation.
18
19 The control types form a hierarchy where properties set on a base type
20 propagate down to the more specific ones. For example, assigning a radius
21 of four to \c abstractButton.background.radius will cause all button
22 types, such as \l button, \l checkBox, and \l radioButton, to get a radius
23 of four.
24
25 The snippets on this page illustrate a few of the key properties that can be
26 used to style each control type, but they are by no means exhaustive. Many other properties
27 are available, as documented in the \l ControlStyle and \l DelegateStyle documentation.
28 In practice, some of them can also be omitted because the
29 \l {Style::fallbackStyle}{fallback style} already supplies sensible defaults.
30 This means that if you simply remove a property from one of the snippets, it
31 might not actually affect its appearance, since it will just be read from the
32 fallback style instead.
33
34 \sa {StyleKit Property Resolution}
35
36 \labs
37*/
38
39/*!
40 \qmlproperty ControlStyle StylableControls::control
41
42 Grouped property for styling all controls.
43
44 \c control is the base type in the control hierarchy, and properties set here
45 serve as defaults for all other control types. For example, setting
46 \c{control.width: 200} makes \e all controls 200 pixels wide,
47 including buttons, scroll indicators and every other control.
48 It also overrides any values inherited from a higher level in the style
49 hierarchy (the \l Style for a \l Theme, or the
50 \l {Style::fallbackStyle}{fallbackStyle} for a \l Style), \e including hover
51 effects and other state-based behavior. Use \c{control} sparingly, and
52 prefer more specific base types like \l abstractButton or \l pane when
53 possible.
54
55 \snippet ControlsSnippets.qml control
56*/
57
58/*!
59 \qmlproperty ControlStyle StylableControls::abstractButton
60
61 Grouped property for styling all button-like controls, including
62 \l [QtQuickControls]{Button}, \l [QtQuickControls]{CheckBox},
63 \l [QtQuickControls]{RadioButton}, \l [QtQuickControls]{Switch}
64 and \l [QtQuickControls]{RoundButton}.
65 Unset properties fall back to \l control.
66
67 \snippet ControlsSnippets.qml abstractButton
68
69 \sa {Qt Labs StyleKit}{Control Types}
70*/
71
72/*!
73 \qmlproperty ControlStyle StylableControls::applicationWindow
74
75 Grouped property for styling \l [QtQuickControls] ApplicationWindow.
76
77 Unset properties fall back to \l control.
78
79 Use \c applicationWindow to set the background color of the window:
80
81 \snippet ControlsSnippets.qml applicationWindow
82
83 \note The application needs to use ApplicationWindow, not Window, for this to take effect.
84*/
85
86/*!
87 \qmlproperty ControlStyle StylableControls::busyIndicator
88
89 Grouped property for styling \l [QtQuickControls]{BusyIndicator}.
90
91 Unset properties fall back to \l control.
92
93 \snippet ControlsSnippets.qml busyIndicator
94
95 StyleKit doesn't provide dedicated properties to style the animation of the
96 spinning indicator. To change the shape or animation of the spinning indicator,
97 you need to implement a custom indicator foreground \l {DelegateStyle::}{delegate}
98 instead:
99
100 \snippet ControlsSnippets.qml busyIndicator delegate
101*/
102
103/*!
104 \qmlproperty ControlStyle StylableControls::button
105
106 Grouped property for styling \l [QtQuickControls]{Button}.
107
108 Unset properties fall back to \l abstractButton.
109
110 \snippet ControlsSnippets.qml button
111*/
112
113/*!
114 \qmlproperty ControlStyle StylableControls::checkBox
115
116 Grouped property for styling \l [QtQuickControls]{CheckBox}.
117
118 Unset properties fall back to \l abstractButton.
119
120 \snippet ControlsSnippets.qml checkBox
121*/
122
123/*!
124 \qmlproperty ControlStyle StylableControls::checkDelegate
125
126 Grouped property for styling \l [QtQuickControls]{CheckDelegate}.
127
128 Unset properties fall back to \l itemDelegate.
129
130 \snippet ControlsSnippets.qml checkDelegate
131*/
132
133/*!
134 \qmlproperty ControlStyle StylableControls::comboBox
135
136 Grouped property for styling \l [QtQuickControls]{ComboBox}.
137
138 Unset properties fall back to \l control.
139
140 \note Style the popup through \l popup, and its items through \l itemDelegate.
141
142 \snippet ControlsSnippets.qml comboBox
143*/
144
145/*!
146 \qmlproperty ControlStyle StylableControls::container
147
148 Grouped property for styling \l [QtQuickControls]{Container}.
149
150 Unset properties fall back to \l control.
151
152 \snippet ControlsSnippets.qml container
153*/
154
155/*!
156 \qmlproperty ControlStyle StylableControls::dayOfWeekRow
157
158 Grouped property for styling \l [QtQuickControls]{DayOfWeekRow}.
159
160 Unset properties fall back to \l control.
161
162 \snippet ControlsSnippets.qml dayOfWeekRow
163*/
164
165/*!
166 \qmlproperty ControlStyle StylableControls::delayButton
167
168 Grouped property for styling \l [QtQuickControls]{DelayButton}.
169
170 For a delay button, the progress is styled through the indicator. By
171 default, the indicator is drawn as a thin bar along the bottom edge of
172 the button, and its foreground fills up as the progress increases.
173
174 Unset properties fall back to \l abstractButton.
175
176 \snippet ControlsSnippets.qml delayButton
177*/
178
179/*!
180 \qmlproperty ControlStyle StylableControls::dial
181
182 Grouped property for styling \l [QtQuickControls]{Dial}.
183
184 Unset properties fall back to \l control.
185
186 \snippet ControlsSnippets.qml dial
187*/
188
189/*!
190 \qmlproperty ControlStyle StylableControls::dialog
191
192 Grouped property for styling \l [QtQuickControls]{Dialog}.
193
194 Unset properties fall back to \l popup.
195
196 \snippet ControlsSnippets.qml dialog
197*/
198
199/*!
200 \qmlproperty ControlStyle StylableControls::dialogButtonBox
201
202 Grouped property for styling \l [QtQuickControls]{DialogButtonBox}.
203
204 Unset properties fall back to \l container.
205
206 \snippet ControlsSnippets.qml dialogButtonBox
207*/
208
209/*!
210 \qmlproperty ControlStyle StylableControls::drawer
211
212 Grouped property for styling \l [QtQuickControls]{Drawer}.
213
214 Unset properties fall back to \l popup.
215
216 \snippet ControlsSnippets.qml drawer
217*/
218
219/*!
220 \qmlproperty ControlStyle StylableControls::flatButton
221
222 Grouped property for styling flat buttons (buttons with no visible
223 background in their normal state). The styling will take effect for
224 a \l [QtQuickControls]{Button} if \l [QtQuickControls]{Button::flat}{Button.flat} is set to \c true.
225
226 Unset properties fall back to \l abstractButton.
227
228 \snippet ControlsSnippets.qml flatButton
229*/
230
231/*!
232 \qmlproperty ControlStyle StylableControls::frame
233
234 Grouped property for styling \l [QtQuickControls]{Frame}.
235
236 Unset properties fall back to \l pane.
237
238 \snippet ControlsSnippets.qml frame
239*/
240
241/*!
242 \qmlproperty ControlStyle StylableControls::groupBox
243
244 Grouped property for styling \l [QtQuickControls]{GroupBox}.
245
246 Unset properties fall back to \l frame.
247
248 \snippet ControlsSnippets.qml groupBox
249*/
250
251/*!
252 \qmlproperty ControlStyle StylableControls::headerViewDelegate
253
254 Grouped property for styling both
255 \l [QtQuickControls]{HorizontalHeaderViewDelegate} and
256 \l [QtQuickControls]{VerticalHeaderViewDelegate}.
257
258 The delegates of a horizontal header view use the style as is. The delegates
259 of a vertical header view additionally apply the
260 \l {ControlStateStyle::vertical}{vertical} state.
261
262 For a horizontal header view delegate, the sort indicator is styled through
263 the indicator. \l {IndicatorStyle::first}{indicator.first} is shown when the
264 column is sorted in ascending order, and \l {IndicatorStyle::second}{indicator.second}
265 when it is sorted in descending order. Only one of them is visible at a
266 time, and only on the header of the column the view is currently sorted by.
267 A vertical header view does not show a sort indicator, so indicator
268 settings in the \c vertical state have no effect.
269
270 Unset properties fall back to \l tableViewDelegate.
271
272 \snippet ControlsSnippets.qml headerViewDelegate
273*/
274
275/*!
276 \qmlproperty ControlStyle StylableControls::itemDelegate
277
278 Grouped property for styling \l [QtQuickControls]{ItemDelegate}.
279
280 Unset properties fall back to \l control.
281
282 \note In Qt Quick Controls, \l [QtQuickControls]{ItemDelegate} inherits from
283 \l [QtQuickControls]{AbstractButton}. In StyleKit, however, \c itemDelegate
284 falls back to \l control rather than \l abstractButton, since delegates are
285 typically \e styled very differently from buttons (flat, no borders or drop shadows, etc.).
286
287 \snippet ControlsSnippets.qml itemDelegate
288*/
289
290/*!
291 \qmlproperty ControlStyle StylableControls::label
292
293 Grouped property for styling \l [QtQuickControls]{Label}.
294
295 Unset properties fall back to \l control.
296
297 \snippet ControlsSnippets.qml label
298*/
299
300/*!
301 \qmlproperty ControlStyle StylableControls::menu
302
303 Grouped property for styling \l [QtQuickControls]{Menu}.
304
305 Unset properties fall back to \l popup.
306
307 \snippet ControlsSnippets.qml menu
308*/
309
310/*!
311 \qmlproperty ControlStyle StylableControls::menuItem
312
313 Grouped property for styling \l [QtQuickControls]{MenuItem}.
314
315 Unset properties fall back to \l control.
316
317 \note In Qt Quick Controls, a \l [QtQuickControls]{MenuItem} inherits from
318    \l [QtQuickControls]{AbstractButton}. In StyleKit, however, \c menuItem
319 falls back to \l control instead of \l abstractButton, since menu items are
320 typically \e styled very differently from regular buttons
321 (flat, no borders or drop shadows, etc.).
322
323 \snippet ControlsSnippets.qml menuItem
324*/
325
326/*!
327 \qmlproperty ControlStyle StylableControls::menuBar
328
329 Grouped property for styling \l [QtQuickControls]{MenuBar}.
330
331 Unset properties fall back to \l container.
332
333 \note Styling \l [QtQuickControls]{MenuBar}, \l [QtQuickControls]{MenuBarItem},
334 and \l [QtQuickControls]{MenuSeparator} normally only affects non-native
335 menu bars. When a MenuBar is implemented as a native menu bar, its delegates
336 are not used for rendering, so StyleKit style properties may have no visual
337 effect. See \l [QtLabsPlatform]{MenuBar} {Native Menu Bars} for details.
338
339 \snippet ControlsSnippets.qml menuBar
340*/
341
342/*!
343 \qmlproperty ControlStyle StylableControls::menuBarItem
344
345 Grouped property for styling menu items in a \l [QtQuickControls]{MenuBar}.
346
347 Unset properties fall back to \l control.
348
349 \note In Qt Quick Controls, a \l [QtQuickControls]{MenuBarItem} inherits from
350 \l [QtQuickControls]{AbstractButton}. In StyleKit, however, \c menuBarItem is a
351 separate control type that falls back to \l control instead of \l abstractButton,
352 since menu bar items are typically styled very differently from regular buttons
353 (flat, no borders or drop shadows, etc.).
354
355 \snippet ControlsSnippets.qml menuBarItem
356*/
357
358/*!
359 \qmlproperty ControlStyle StylableControls::menuSeparator
360
361 Grouped property for styling \l [QtQuickControls]{MenuSeparator}.
362
363 Unset properties fall back to \l control.
364
365 \snippet ControlsSnippets.qml menuSeparator
366*/
367
368/*!
369 \qmlproperty ControlStyle StylableControls::monthGrid
370
371 Grouped property for styling \l [QtQuickControls]{MonthGrid}.
372
373 Unset properties fall back to \l control.
374
375 \snippet ControlsSnippets.qml monthGrid
376*/
377
378/*!
379 \qmlproperty ControlStyle StylableControls::page
380
381 Grouped property for styling \l [QtQuickControls]{Page}.
382
383 Unset properties fall back to \l pane.
384
385 Note that the \l [QtQuickControls]{Page::header}{header} and
386 \l [QtQuickControls]{Page::footer}{footer} of a \l [QtQuickControls]{Page} are
387 typically set by the application to a \l [QtQuickControls]{ToolBar} or
388 \l [QtQuickControls]{TabBar}, and those controls are styled separately.
389 To give a \l [QtQuickControls]{ToolBar} alternative styling when used inside
390 a \l [QtQuickControls]{Page}, use a \l StyleVariation:
391
392 \snippet ControlsSnippets.qml page
393*/
394
395/*!
396 \qmlproperty ControlStyle StylableControls::pageIndicator
397
398 Grouped property for styling \l [QtQuickControls]{PageIndicator}.
399
400 Unset properties fall back to \l control.
401
402 \snippet ControlsSnippets.qml pageIndicator
403*/
404
405/*!
406 \qmlproperty ControlStyle StylableControls::pane
407
408 Grouped property for styling \l [QtQuickControls]{Pane}.
409
410 Unset properties fall back to \l control.
411
412 \snippet ControlsSnippets.qml pane
413*/
414
415/*!
416 \qmlproperty ControlStyle StylableControls::popup
417
418 Grouped property for styling \l [QtQuickControls]{Popup}.
419
420 Unset properties fall back to \l control.
421
422 \snippet ControlsSnippets.qml popup
423*/
424
425/*!
426 \qmlproperty ControlStyle StylableControls::progressBar
427
428 Grouped property for styling \l [QtQuickControls]{ProgressBar}.
429 For a progress bar, the groove is styled through the indicator, while the progress
430 track is styled through the indicator's foreground.
431
432 Unset properties fall back to \l control.
433
434 \snippet ControlsSnippets.qml progressBar
435
436 StyleKit doesn't provide a dedicated property to style the indeterminate animation
437 of a progress bar. To change the animation, you need to implement a custom indicator
438 foreground \l {DelegateStyle::}{delegate} instead:
439
440 \snippet ControlsSnippets.qml progressBar indeterminate
441*/
442
443/*!
444 \qmlproperty ControlStyle StylableControls::radioButton
445
446 Grouped property for styling \l [QtQuickControls]{RadioButton}.
447
448 Unset properties fall back to \l abstractButton.
449
450 \snippet ControlsSnippets.qml radioButton
451*/
452
453/*!
454 \qmlproperty ControlStyle StylableControls::radioDelegate
455
456 Grouped property for styling \l [QtQuickControls]{RadioDelegate}.
457
458 Unset properties fall back to \l itemDelegate.
459
460 \snippet ControlsSnippets.qml radioDelegate
461*/
462
463/*!
464 \qmlproperty ControlStyle StylableControls::roundButton
465
466 Grouped property for styling \l [QtQuickControls]{RoundButton}.
467
468 Unset properties fall back to \l abstractButton.
469
470 \snippet ControlsSnippets.qml roundButton
471*/
472
473/*!
474 \qmlproperty ControlStyle StylableControls::scrollBar
475
476 Grouped property for styling \l [QtQuickControls]{ScrollBar}.
477 The groove is styled through \l {ControlStyleProperties::}{background}, and the
478 handle through \l {ControlStyleProperties::}{indicator}.
479
480 Unset properties fall back to \l control.
481
482 \snippet ControlsSnippets.qml scrollBar
483*/
484
485/*!
486 \qmlproperty ControlStyle StylableControls::scrollIndicator
487
488 Grouped property for styling \l [QtQuickControls]{ScrollIndicator}.
489 The groove is styled through \l {ControlStyleProperties::}{background}, and the
490 handle through \l {ControlStyleProperties::}{indicator}.
491
492 Unset properties fall back to \l control.
493
494 \snippet ControlsSnippets.qml scrollIndicator
495*/
496
497/*!
498 \qmlproperty ControlStyle StylableControls::scrollView
499
500 Grouped property for styling \l [QtQuickControls]{ScrollView}.
501
502 ScrollView itself has no visual delegates to style. Its scroll bars can be
503 styled separately through the \l scrollBar property. But you can use
504 \l {ControlStateStyle::padding}{padding} to control the space between
505 the scroll bars and the content area.
506
507 Unset properties fall back to \l control.
508
509 \snippet ControlsSnippets.qml scrollView
510*/
511
512/*!
513 \qmlproperty ControlStyle StylableControls::searchField
514
515 Grouped property for styling \l [QtQuickControls]{SearchField}.
516
517 Unset properties fall back to \l control.
518
519 \snippet ControlsSnippets.qml searchField
520
521*/
522
523/*!
524 \qmlproperty ControlStyle StylableControls::slider
525
526 Grouped property for styling \l [QtQuickControls]{Slider}.
527 For a slider, the groove is styled through the indicator, while the progress
528 track is styled through the indicator's foreground.
529
530 Unset properties fall back to \l control.
531
532 For vertical sliders, swap the \l {DelegateStyle::width}{width}
533 and \l {DelegateStyle::height}{height} of the relevant delegates
534 so that the control is taller than it is wide, as shown in the snippet below.
535
536 \snippet ControlsSnippets.qml slider
537*/
538
539/*!
540 \qmlproperty ControlStyle StylableControls::spinBox
541
542 Grouped property for styling \l [QtQuickControls]{SpinBox}.
543
544 Unset properties fall back to \l control.
545
546 \snippet ControlsSnippets.qml spinBox
547
548 \note It's currently only possible to position the up and down buttons to
549 be on the left or right side of the control, but not on top of each other.
550*/
551
552/*!
553 \qmlproperty ControlStyle StylableControls::splitView
554
555 Grouped property for styling \l [QtQuickControls]{SplitView}.
556
557 Unset properties fall back to \l container.
558
559 \snippet ControlsSnippets.qml splitView
560*/
561
562/*!
563 \qmlproperty ControlStyle StylableControls::swipeDelegate
564
565 Grouped property for styling \l [QtQuickControls]{SwipeDelegate}.
566
567 Unset properties fall back to \l itemDelegate.
568
569 \snippet ControlsSnippets.qml swipeDelegate
570*/
571
572/*!
573 \qmlproperty ControlStyle StylableControls::switchControl
574
575 Grouped property for styling \l [QtQuickControls]{Switch}.
576
577 Unset properties fall back to \l abstractButton.
578
579 \snippet ControlsSnippets.qml switchControl
580*/
581
582/*!
583 \qmlproperty ControlStyle StylableControls::switchDelegate
584
585 Grouped property for styling \l [QtQuickControls]{SwitchDelegate}.
586
587 Unset properties fall back to \l itemDelegate.
588
589 \snippet ControlsSnippets.qml switchDelegate
590*/
591
592/*!
593 \qmlproperty ControlStyle StylableControls::tabBar
594
595 Grouped property for styling \l [QtQuickControls]{TabBar}.
596
597 Unset properties fall back to \l container.
598
599 \snippet ControlsSnippets.qml tabBar
600*/
601
602/*!
603 \qmlproperty ControlStyle StylableControls::tabButton
604
605 Grouped property for styling \l [QtQuickControls]{TabButton}.
606
607 Unset properties fall back to \l abstractButton.
608
609 \snippet ControlsSnippets.qml tabButton
610*/
611
612/*!
613 \qmlproperty ControlStyle StylableControls::tableViewDelegate
614
615 Grouped property for styling \l [QtQuickControls]{TableViewDelegate}.
616
617 Unset properties fall back to \l itemDelegate.
618
619 \snippet ControlsSnippets.qml tableViewDelegate
620*/
621
622/*!
623 \qmlproperty ControlStyle StylableControls::textArea
624
625 Grouped property for styling \l [QtQuickControls]{TextArea}.
626
627 Unset properties fall back to \l textInput.
628
629 \snippet ControlsSnippets.qml textArea
630*/
631
632/*!
633 \qmlproperty ControlStyle StylableControls::textField
634
635 Grouped property for styling \l [QtQuickControls]{TextField}.
636
637 Unset properties fall back to \l textInput.
638
639 \snippet ControlsSnippets.qml textField
640*/
641
642/*!
643 \qmlproperty ControlStyle StylableControls::textInput
644
645 Grouped property for styling all text input controls, including
646 \l [QtQuickControls]{TextField} and \l [QtQuickControls]{TextArea}.
647
648 Unset properties fall back to \l control.
649
650 \snippet ControlsSnippets.qml textInput
651*/
652
653/*!
654 \qmlproperty ControlStyle StylableControls::toolBar
655
656 Grouped property for styling \l [QtQuickControls]{ToolBar}.
657
658 Unset properties fall back to \l pane.
659
660 \snippet ControlsSnippets.qml toolBar
661*/
662
663/*!
664 \qmlproperty ControlStyle StylableControls::toolButton
665
666 Grouped property for styling \l [QtQuickControls]{ToolButton}.
667
668 Unset properties fall back to \l abstractButton.
669
670 \snippet ControlsSnippets.qml toolButton
671*/
672
673/*!
674 \qmlproperty ControlStyle StylableControls::toolSeparator
675
676 Grouped property for styling \l [QtQuickControls]{ToolSeparator}.
677
678 Unset properties fall back to \l control.
679
680 For vertical separators, swap the \l {DelegateStyle::width}{width}
681 and \l {DelegateStyle::height}{height} of the relevant delegates
682 so that the control is taller than it is wide, as shown in the snippet below.
683
684 \snippet ControlsSnippets.qml toolSeparator
685*/
686
687/*!
688 \qmlproperty ControlStyle StylableControls::toolTip
689
690 Grouped property for styling \l [QtQuickControls]{ToolTip}.
691
692 Unset properties fall back to \l popup.
693
694 \snippet ControlsSnippets.qml toolTip
695*/
696
697/*!
698 \qmlproperty ControlStyle StylableControls::treeViewDelegate
699
700 Grouped property for styling \l [QtQuickControls]{TreeViewDelegate}.
701
702 Unset properties fall back to \l itemDelegate.
703
704 \snippet ControlsSnippets.qml treeViewDelegate
705*/
706
707/*!
708 \qmlproperty ControlStyle StylableControls::tumbler
709
710 Grouped property for styling \l [QtQuickControls]{Tumbler}.
711
712 Unset properties fall back to \l control.
713
714 \snippet ControlsSnippets.qml tumbler
715*/
716
717/*!
718 \qmlproperty ControlStyle StylableControls::weekNumberColumn
719
720 Grouped property for styling \l [QtQuickControls]{WeekNumberColumn}.
721
722 Unset properties fall back to \l control.
723
724 \snippet ControlsSnippets.qml weekNumberColumn
725*/
726
727using namespace Qt::StringLiterals;
728
729QQStyleKitControls::QQStyleKitControls(QObject *parent)
730 : QObject(parent)
731{
732}
733
734QQmlListProperty<QObject> QQStyleKitControls::data()
735{
736 return QQmlListProperty<QObject>(this, &m_data);
737}
738
739const QList<QObject *> QQStyleKitControls::children() const
740{
741 return m_data;
742}
743
744/*!
745 \qmlmethod ControlStyle StylableControls::getControlStyle(controlType)
746
747 Returns the \l ControlStyle for the given \a controlType, or \c null, if
748 no \l ControlStyle for the type has been defined.
749
750 \a controlType can be one of the built-in types documented by
751 \l {StyleReader::controlType}{StyleReader.controlType}, or the
752 \l {CustomControl::controlType}{controlType} of a \l CustomControl.
753
754 This function can be used to, for example, read or write a property on
755 a \l CustomControl's style at runtime:
756
757 \snippet ControlsSnippets.qml getControlStyle
758
759 \snippet ControlsSnippets.qml getControlStyle-function
760
761 If \a controlType is a built-in type (such as \c {StyleReader.Button}),
762 using for example \c {myStyle.button} or \c {myStyle.getControlStyle(StyleReader.Button)}
763 to get the \l ControlStyle is \e almost equivalent.
764 The difference is that the former will lazily create a \l ControlStyle if
765 it's not yet defined, while the latter will instead return \c null.
766 This means that for example \c {myStyle.button.padding = 10} is always
767 safe, while \c {myStyle.getControlStyle(StyleReader.Button).padding = 10} will
768 fail if \c {myStyle.button} has not been defined in the \l Style.
769
770 \sa CustomControl, StyleReader
771*/
772
773/* Lazy-create the controls that the style is actually using, when accessed
774 * from the style/application (e.g from Style or Theme). We don't lazy
775 * create any controls while resolving style properties, as undefined controls would
776 * anyway not contain any property overrides. The properties have setters too, to
777 * allow the style/application to share custom ControlStyle the classical
778 * way, e.g button: ControlStyle { id: button }. */
779QQStyleKitControl* QQStyleKitControls::getControlStyle(QQStyleKitExtendableControlType controlType) const
780{
781 return m_controls.value(controlType, nullptr);
782}
783
784#define IMPLEMENT_ACCESSORS(NAME, TYPE) QQStyleKitControl
785 *QQStyleKitControls::NAME() const \
786{
787 if (!m_controls.contains(TYPE)) {
788 auto *self = const_cast<QQStyleKitControls *>(this);
789 auto *control = new QQStyleKitControl(self);
790 self->m_controls.insert(TYPE, control);
791 }
792 return m_controls[TYPE]; \
793}void
794 QQStyleKitControls::set_ ## NAME(QQStyleKitControl *control) \
795{
796 m_controls.insert(TYPE, control); \
797}
798
799
800IMPLEMENT_ACCESSORS(abstractButton, QQStyleKitReader::ControlType::AbstractButton)
801IMPLEMENT_ACCESSORS(applicationWindow, QQStyleKitReader::ControlType::ApplicationWindow)
802IMPLEMENT_ACCESSORS(control, QQStyleKitReader::ControlType::Control)
803IMPLEMENT_ACCESSORS(busyIndicator, QQStyleKitReader::ControlType::BusyIndicator)
804IMPLEMENT_ACCESSORS(button, QQStyleKitReader::ControlType::Button)
805IMPLEMENT_ACCESSORS(flatButton, QQStyleKitReader::ControlType::FlatButton)
806IMPLEMENT_ACCESSORS(checkBox, QQStyleKitReader::ControlType::CheckBox)
807IMPLEMENT_ACCESSORS(checkDelegate, QQStyleKitReader::ControlType::CheckDelegate)
808IMPLEMENT_ACCESSORS(comboBox, QQStyleKitReader::ControlType::ComboBox)
809IMPLEMENT_ACCESSORS(container, QQStyleKitReader::ControlType::Container)
810IMPLEMENT_ACCESSORS(dayOfWeekRow, QQStyleKitReader::ControlType::DayOfWeekRow)
811IMPLEMENT_ACCESSORS(delayButton, QQStyleKitReader::ControlType::DelayButton)
812IMPLEMENT_ACCESSORS(dial, QQStyleKitReader::ControlType::Dial)
813IMPLEMENT_ACCESSORS(dialog, QQStyleKitReader::ControlType::Dialog)
814IMPLEMENT_ACCESSORS(dialogButtonBox, QQStyleKitReader::ControlType::DialogButtonBox)
815IMPLEMENT_ACCESSORS(drawer, QQStyleKitReader::ControlType::Drawer)
816IMPLEMENT_ACCESSORS(headerViewDelegate, QQStyleKitReader::ControlType::HeaderViewDelegate)
817IMPLEMENT_ACCESSORS(progressBar, QQStyleKitReader::ControlType::ProgressBar)
818IMPLEMENT_ACCESSORS(scrollBar, QQStyleKitReader::ControlType::ScrollBar)
819IMPLEMENT_ACCESSORS(scrollIndicator, QQStyleKitReader::ControlType::ScrollIndicator)
820IMPLEMENT_ACCESSORS(scrollView, QQStyleKitReader::ControlType::ScrollView)
821IMPLEMENT_ACCESSORS(searchField, QQStyleKitReader::SearchField)
822IMPLEMENT_ACCESSORS(slider, QQStyleKitReader::ControlType::Slider)
823IMPLEMENT_ACCESSORS(spinBox, QQStyleKitReader::ControlType::SpinBox)
824IMPLEMENT_ACCESSORS(splitView, QQStyleKitReader::ControlType::SplitView)
825IMPLEMENT_ACCESSORS(swipeDelegate, QQStyleKitReader::ControlType::SwipeDelegate)
826IMPLEMENT_ACCESSORS(switchControl, QQStyleKitReader::ControlType::SwitchControl)
827IMPLEMENT_ACCESSORS(switchDelegate, QQStyleKitReader::ControlType::SwitchDelegate)
828IMPLEMENT_ACCESSORS(tabBar, QQStyleKitReader::ControlType::TabBar)
829IMPLEMENT_ACCESSORS(tabButton, QQStyleKitReader::ControlType::TabButton)
830IMPLEMENT_ACCESSORS(tableViewDelegate, QQStyleKitReader::ControlType::TableViewDelegate)
831IMPLEMENT_ACCESSORS(textField, QQStyleKitReader::ControlType::TextField)
832IMPLEMENT_ACCESSORS(textInput, QQStyleKitReader::ControlType::TextInput)
833IMPLEMENT_ACCESSORS(toolBar, QQStyleKitReader::ControlType::ToolBar)
834IMPLEMENT_ACCESSORS(toolButton, QQStyleKitReader::ControlType::ToolButton)
835IMPLEMENT_ACCESSORS(toolSeparator, QQStyleKitReader::ControlType::ToolSeparator)
836IMPLEMENT_ACCESSORS(toolTip, QQStyleKitReader::ControlType::ToolTip)
837IMPLEMENT_ACCESSORS(treeViewDelegate, QQStyleKitReader::ControlType::TreeViewDelegate)
838IMPLEMENT_ACCESSORS(tumbler, QQStyleKitReader::ControlType::Tumbler)
839IMPLEMENT_ACCESSORS(radioButton, QQStyleKitReader::ControlType::RadioButton)
840IMPLEMENT_ACCESSORS(radioDelegate, QQStyleKitReader::ControlType::RadioDelegate)
841IMPLEMENT_ACCESSORS(roundButton, QQStyleKitReader::ControlType::RoundButton)
842IMPLEMENT_ACCESSORS(itemDelegate, QQStyleKitReader::ControlType::ItemDelegate)
843IMPLEMENT_ACCESSORS(popup, QQStyleKitReader::ControlType::Popup)
844IMPLEMENT_ACCESSORS(pane, QQStyleKitReader::ControlType::Pane)
845IMPLEMENT_ACCESSORS(page, QQStyleKitReader::ControlType::Page)
846IMPLEMENT_ACCESSORS(pageIndicator, QQStyleKitReader::ControlType::PageIndicator)
847IMPLEMENT_ACCESSORS(frame, QQStyleKitReader::ControlType::Frame)
848IMPLEMENT_ACCESSORS(label, QQStyleKitReader::ControlType::Label)
849IMPLEMENT_ACCESSORS(groupBox, QQStyleKitReader::ControlType::GroupBox)
850IMPLEMENT_ACCESSORS(textArea, QQStyleKitReader::ControlType::TextArea)
851IMPLEMENT_ACCESSORS(menu, QQStyleKitReader::ControlType::Menu)
852IMPLEMENT_ACCESSORS(menuBar, QQStyleKitReader::ControlType::MenuBar)
853IMPLEMENT_ACCESSORS(menuBarItem, QQStyleKitReader::ControlType::MenuBarItem)
854IMPLEMENT_ACCESSORS(menuItem, QQStyleKitReader::ControlType::MenuItem)
855IMPLEMENT_ACCESSORS(menuSeparator, QQStyleKitReader::ControlType::MenuSeparator)
856IMPLEMENT_ACCESSORS(monthGrid, QQStyleKitReader::ControlType::MonthGrid)
857IMPLEMENT_ACCESSORS(weekNumberColumn, QQStyleKitReader::ControlType::WeekNumberColumn)
858
859#undef IMPLEMENT_ACCESSORS
860
861void QQStyleKitControls::componentComplete()
862{
863 for (auto *obj : children()) {
864 if (auto *customControl = qobject_cast<QQStyleKitCustomControl *>(obj)) {
865 const QQStyleKitExtendableControlType type = customControl->controlType();
866 const QQStyleKitExtendableControlType reserved
867 = QQStyleKitExtendableControlType(QQStyleKitReader::ControlType::Unspecified);
868 if (type >= reserved)
869 qmlWarning(this) << "CustomControls must use a controlType less than " << reserved;
870 if (m_controls.contains(type))
871 qmlWarning(this) << "CustomControl registered more than once: " << type;
872 m_controls.insert(type, customControl);
873 }
874 }
875}
876
877QT_END_NAMESPACE
878
879#include "moc_qqstylekitcontrols_p.cpp"
Combined button and popup list for selecting options.
#define IMPLEMENT_ACCESSORS(NAME, TYPE)