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-reference-buttons.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-buttons.html
6 \title Styling Buttons and Input Widgets
7 \brief The style elements, states, and options of push buttons, checkboxes,
8 radio buttons, tool buttons, combo boxes, spin boxes, sliders, scroll bars,
9 and progress bars.
10
11 This page is part of the \l{Widget Style Reference}. For an explanation
12 of the element trees, screenshots, and tables, see that page. The common
13 state flags and members that every widget sets are listed in
14 \l{How a Style Draws a Widget#Common state flags and members}{How a Style
15 Draws a Widget}.
16
17 \section1 Push buttons
18
19 \l QPushButton draws a single control element, \c CE_PushButton, with a
20 \l QStyleOptionButton. \l QCommonStyle splits it into the bevel, the label,
21 and the focus frame:
22
23 \list
24 \li \c CE_PushButton
25 \list
26 \li \c CE_PushButtonBevel (\c PM_ButtonDefaultIndicator,
27 \c PM_MenuButtonIndicator)
28 \list
29 \li \c PE_FrameDefaultButton, for the default button
30 \li \c PE_PanelButtonCommand
31 \li \c PE_IndicatorArrowDown, for a button with a menu
32 \endlist
33 \li \c CE_PushButtonLabel (\c SE_PushButtonContents,
34 \c PM_ButtonShiftHorizontal, \c PM_ButtonShiftVertical,
35 \c PM_ButtonIconSize)
36 \li \c PE_FrameFocusRect (\c SE_PushButtonFocusRect)
37 \endlist
38 \endlist
39
40 The button calculates its size hint with \c CT_PushButton and
41 \c PM_ButtonMargin. Element bounds vary between styles. In \l QCommonStyle,
42 \c PE_FrameDefaultButton gets the whole bevel rectangle, and so does
43 \c PE_PanelButtonCommand, except on an auto-default button, where the panel
44 shrinks by \c PM_ButtonDefaultIndicator on each side.
45
46 \image styles/pushbutton.webp
47 {Two push buttons with the bevel, label, and focus rectangle
48 outlined}
49
50 \l QPushButton sets these state flags:
51
52 \table 90%
53 \header
54 \li State
55 \li Set when
56 \row
57 \li \c State_Sunken
58 \li The button is pressed, or its menu is shown.
59 \row
60 \li \c State_On
61 \li The button is checked.
62 \row
63 \li \c State_Raised
64 \li The button isn't flat and isn't pressed.
65 \endtable
66
67 The other members of \l QStyleOptionButton are:
68
69 \table 90%
70 \header
71 \li Member
72 \li Description
73 \row
74 \li features
75 \li Flags of the \l QStyleOptionButton::ButtonFeature enum that
76 describe the button: flat, default, auto-default, with a menu,
77 or a command link button.
78 \row
79 \li icon
80 \li The button's \l QIcon, if any.
81 \row
82 \li iconSize
83 \li The size of the icon.
84 \row
85 \li text
86 \li The button text.
87 \endtable
88
89 \section1 Checkboxes and radio buttons
90
91 \l QCheckBox and \l QRadioButton have identical structures. Both use
92 \l QStyleOptionButton and draw one control element, \c CE_CheckBox or
93 \c CE_RadioButton. \l QCommonStyle draws the indicator, the label, and the
94 focus frame:
95
96 \list
97 \li \c CE_CheckBox
98 \list
99 \li \c PE_IndicatorCheckBox (\c SE_CheckBoxIndicator,
100 \c PM_IndicatorWidth, \c PM_IndicatorHeight)
101 \li \c CE_CheckBoxLabel (\c SE_CheckBoxContents,
102 \c PM_CheckBoxLabelSpacing)
103 \li \c PE_FrameFocusRect (\c SE_CheckBoxFocusRect)
104 \endlist
105 \li \c CE_RadioButton
106 \list
107 \li \c PE_IndicatorRadioButton (\c SE_RadioButtonIndicator,
108 \c PM_ExclusiveIndicatorWidth, \c PM_ExclusiveIndicatorHeight)
109 \li \c CE_RadioButtonLabel (\c SE_RadioButtonContents,
110 \c PM_RadioButtonLabelSpacing)
111 \li \c PE_FrameFocusRect (\c SE_RadioButtonFocusRect)
112 \endlist
113 \endlist
114
115 The size hints use \c CT_CheckBox and \c CT_RadioButton.
116 \l{Styling a Checkbox: A Walkthrough} traces the drawing of a checkbox
117 through the widget and \l QCommonStyle code.
118
119 \image styles/checkbox.webp
120 {Checkbox and radio button with the indicator, label, and focus
121 rectangle outlined}
122
123 The buttons set these state flags:
124
125 \table 90%
126 \header
127 \li State
128 \li Set when
129 \row
130 \li \c State_Sunken
131 \li The button is pressed. The clickable area is
132 \c SE_CheckBoxClickRect or \c SE_RadioButtonClickRect, which in
133 \l QCommonStyle covers the label as well as the indicator.
134 \row
135 \li \c State_NoChange
136 \li The checkbox is partially checked (a tristate checkbox).
137 \row
138 \li \c State_On
139 \li The button is checked.
140 \row
141 \li \c State_Off
142 \li The button is unchecked.
143 \endtable
144
145 The other members of \l QStyleOptionButton are listed under
146 \l{Push buttons}.
147
148 \section1 Tool buttons
149
150 \l QToolButton draws one complex control, \c CC_ToolButton, with a
151 \l QStyleOptionToolButton. It has two subcontrols: the button itself and,
152 for a button with \l{QToolButton::MenuButtonPopup}{a menu button}, the menu
153 indicator.
154
155 \list
156 \li \c CC_ToolButton
157 \list
158 \li \c SC_ToolButton
159 \list
160 \li \c PE_PanelButtonTool (\c PM_DefaultFrameWidth)
161 \li \c PE_FrameFocusRect
162 \li \c CE_ToolButtonLabel (\c PM_ButtonShiftHorizontal,
163 \c PM_ButtonShiftVertical)
164 \endlist
165 \li \c SC_ToolButtonMenu (\c PM_MenuButtonIndicator)
166 \list
167 \li \c PE_IndicatorButtonDropDown
168 \li \c PE_IndicatorArrowDown
169 \endlist
170 \endlist
171 \endlist
172
173 For \l{QToolButton::InstantPopup}{instant} and
174 \l{QToolButton::DelayedPopup}{delayed} popups there is no menu subcontrol,
175 so \l QCommonStyle draws \c PE_IndicatorArrowDown in the corner of the
176 button rectangle instead. The size hint uses \c CT_ToolButton, and the
177 button consults \c SH_ToolButton_PopupDelay and \c SH_ToolButtonStyle. Tool
178 buttons in a toolbar take their icon size from the toolbar. Standalone
179 buttons use \c PM_ButtonIconSize.
180
181 \image styles/toolbutton.webp
182 {Tool button with an icon, text, and menu indicator, with the button
183 and the menu subcontrol outlined}
184
185 \l QToolButton sets these state flags:
186
187 \table 90%
188 \header
189 \li State
190 \li Set when
191 \row
192 \li \c State_AutoRaise
193 \li The \l{QToolButton::autoRaise}{autoRaise} property is set.
194 \row
195 \li \c State_Raised
196 \li The button isn't checked or pressed. \l QCommonStyle then clears
197 the flag again if \c State_AutoRaise is set and the mouse isn't
198 over the button.
199 \row
200 \li \c State_Sunken
201 \li The button is pressed, or its menu is shown.
202 \row
203 \li \c State_On
204 \li The button is checkable and checked.
205 \endtable
206
207 The other members of \l QStyleOptionToolButton are:
208
209 \table 90%
210 \header
211 \li Member
212 \li Description
213 \row
214 \li arrowType
215 \li A \l{Qt::ArrowType} value that gives the direction of the arrow
216 drawn instead of an icon, if any.
217 \row
218 \li features
219 \li Flags of the \l QStyleOptionToolButton::ToolButtonFeature enum:
220 whether the button shows an arrow, has a menu button, or has a
221 delayed popup.
222 \row
223 \li font
224 \li The \l QFont of the button label.
225 \row
226 \li icon
227 \li The \l QIcon of the button.
228 \row
229 \li iconSize
230 \li The size of the icon.
231 \row
232 \li pos
233 \li The position of the button, as given by \l QWidget::pos().
234 \row
235 \li text
236 \li The button text.
237 \row
238 \li toolButtonStyle
239 \li A \l{Qt::ToolButtonStyle} value that decides whether the button
240 shows the icon, the text, or both.
241 \endtable
242
243 \section1 Combo boxes
244
245 \l QComboBox draws the button and the label with \c CC_ComboBox and
246 \c CE_ComboBoxLabel, both with a \l QStyleOptionComboBox. \l QCommonStyle
247 omits the text of the label for an editable box, where the \l QLineEdit
248 child draws it. The popup list is an item view drawn by a
249 \l{Delegate Classes}{delegate}, but the style controls its size and position
250 with \c SC_ComboBoxListBoxPopup. For an editable box, the style decides
251 where the line edit goes with \c SC_ComboBoxEditField; the field itself is a
252 \l QLineEdit child.
253
254 \list
255 \li \c CC_ComboBox (\c PM_ComboBoxFrameWidth)
256 \list
257 \li \c SC_ComboBoxFrame
258 \li \c SC_ComboBoxArrow (\c PE_IndicatorArrowDown)
259 \li \c SC_ComboBoxEditField
260 \li \c SC_ComboBoxListBoxPopup, for positioning the popup
261 \endlist
262 \li \c CE_ComboBoxLabel (\c SC_ComboBoxEditField)
263 \endlist
264
265 The size hint uses \c CT_ComboBox. Style hints such as \c SH_ComboBox_Popup,
266 \c SH_ComboBox_PopupFrameStyle, and \c SH_ComboBox_UseNativePopup decide how
267 the popup looks and behaves.
268
269 \image styles/combobox.webp
270 {Combo box with the frame, edit field, and arrow subcontrols
271 outlined}
272
273 \l QComboBox sets these state flags:
274
275 \table 90%
276 \header
277 \li State
278 \li Set when
279 \row
280 \li \c State_Selected
281 \li The box isn't editable and has focus.
282 \row
283 \li \c State_Sunken
284 \li \c SC_ComboBoxArrow is active.
285 \row
286 \li \c State_On
287 \li The popup list is visible.
288 \endtable
289
290 The other members of \l QStyleOptionComboBox are:
291
292 \table 90%
293 \header
294 \li Member
295 \li Description
296 \row
297 \li currentIcon
298 \li The icon of the current item.
299 \row
300 \li currentText
301 \li The text of the current item.
302 \row
303 \li editable
304 \li Whether the combo box is editable.
305 \row
306 \li frame
307 \li Whether the combo box has a frame.
308 \row
309 \li iconSize
310 \li The size of the current item's icon.
311 \row
312 \li popupRect
313 \li The bounding rectangle of the popup list.
314 \row
315 \li textAlignment
316 \li The alignment of the text in the label.
317 \endtable
318
319 \section1 Spin boxes
320
321 \l QSpinBox, \l QDoubleSpinBox, and \l QDateTimeEdit draw \c CC_SpinBox with
322 a \l QStyleOptionSpinBox. The edit field is a \l QLineEdit child whose
323 geometry the style returns for \c SC_SpinBoxEditField.
324
325 \list
326 \li \c CC_SpinBox (\c PM_SpinBoxFrameWidth)
327 \list
328 \li \c SC_SpinBoxFrame
329 \li \c SC_SpinBoxUp
330 \list
331 \li \c PE_PanelButtonBevel
332 \li \c PE_IndicatorSpinUp or \c PE_IndicatorSpinPlus, depending on
333 \l{QAbstractSpinBox::buttonSymbols}{buttonSymbols}
334 \endlist
335 \li \c SC_SpinBoxDown
336 \list
337 \li \c PE_PanelButtonBevel
338 \li \c PE_IndicatorSpinDown or \c PE_IndicatorSpinMinus
339 \endlist
340 \li \c SC_SpinBoxEditField
341 \endlist
342 \endlist
343
344 A style doesn't have to draw the button panels with \c PE_PanelButtonBevel.
345 The size hint uses \c CT_SpinBox, and the widget consults hints such as
346 \c SH_SpinBox_ButtonsInsideFrame, \c SH_SpinBox_StepModifier, and
347 \c SH_SpinControls_DisableOnBounds.
348
349 \image styles/spinbox.webp
350 {Spin box with the frame, edit field, up button, and down button sub
351 controls outlined}
352
353 The spin box sets this state flag:
354
355 \table 90%
356 \header
357 \li State
358 \li Set when
359 \row
360 \li \c State_Sunken
361 \li The \c SC_SpinBoxUp or \c SC_SpinBoxDown subcontrol is pressed.
362 \endtable
363
364 The other members of \l QStyleOptionSpinBox are:
365
366 \table 90%
367 \header
368 \li Member
369 \li Description
370 \row
371 \li frame
372 \li Whether the spin box draws a frame.
373 \row
374 \li buttonSymbols
375 \li A \l QAbstractSpinBox::ButtonSymbols value that selects the
376 symbols on the buttons: arrows, plus and minus, or none.
377 \row
378 \li stepEnabled
379 \li \l QAbstractSpinBox::StepEnabled flags that tell which of the
380 buttons can step the value. A button that can't step is drawn
381 disabled.
382 \endtable
383
384 \section1 Sliders
385
386 \l QSlider draws \c CC_Slider with a \l QStyleOptionSlider. It calculates
387 its size hint from \c PM_SliderThickness and \c CT_Slider, and its minimum
388 size hint from \c PM_SliderLength.
389
390 \list
391 \li \c CC_Slider (\c PM_SliderLength, \c PM_SliderControlThickness,
392 \c PM_SliderTickmarkOffset, \c PM_SliderSpaceAvailable)
393 \list
394 \li \c SC_SliderGroove
395 \li \c SC_SliderHandle
396 \li \c SC_SliderTickmarks
397 \endlist
398 \endlist
399
400 \l QCommonStyle draws only the tick marks; the groove and the handle are
401 always style specific. Styles don't have to return a rectangle for
402 \c SC_SliderTickmarks. Fusion returns an empty one and draws the ticks below
403 the handle, in the area outlined in the screenshot. The widget consults
404 \c SH_Slider_AbsoluteSetButtons, \c SH_Slider_PageSetButtons, and
405 \c SH_Slider_SnapToValue.
406
407 \image styles/slider.webp
408 {Horizontal slider with tick marks, with the groove, handle, and tick
409 mark subcontrols outlined}
410
411 \l QDial uses the same option and draws \c CC_Dial with the subcontrols
412 \c SC_DialGroove, \c SC_DialHandle, and \c SC_DialTickmarks.
413
414 \l QSlider sets these state flags:
415
416 \table 90%
417 \header
418 \li State
419 \li Set when
420 \row
421 \li \c State_Horizontal
422 \li The slider is horizontal.
423 \row
424 \li \c State_Sunken
425 \li Any subcontrol is pressed, including the groove.
426 \c activeSubControls tells which one.
427 \endtable
428
429 \l QStyleOptionSlider serves all \l{QAbstractSlider}s. Its members are:
430
431 \table 90%
432 \header
433 \li Member
434 \li Description
435 \row
436 \li orientation
437 \li A \l{Qt::Orientation} value: vertical or horizontal.
438 \row
439 \li minimum
440 \li The minimum value.
441 \row
442 \li maximum
443 \li The maximum value.
444 \row
445 \li tickPosition
446 \li A \l QSlider::TickPosition value that tells where the tick marks
447 are drawn.
448 \row
449 \li tickInterval
450 \li The distance between tick marks, in slider values.
451 \row
452 \li upsideDown
453 \li The direction in which the value increases. All abstract sliders
454 use this member instead of \l QStyleOption::direction.
455 \row
456 \li sliderPosition
457 \li The position of the handle, as a slider value. It equals
458 \c sliderValue while \l{QAbstractSlider::tracking}{tracking} is
459 on; otherwise the value only updates when the handle is
460 released.
461 \row
462 \li sliderValue
463 \li The current value.
464 \row
465 \li singleStep
466 \li The amount the value changes on a single step, such as an arrow
467 key press.
468 \row
469 \li pageStep
470 \li The amount the value changes on a page step, such as a click in
471 the groove.
472 \row
473 \li notchTarget
474 \li The preferred distance between notches, in pixels. Used by
475 \l QDial.
476 \row
477 \li dialWrapping
478 \li Whether the dial wraps around. Used by \l QDial.
479 \row
480 \li keyboardModifiers
481 \li The modifier keys that were held during the last mouse event,
482 for styles that let modifiers change the drag behavior.
483 \endtable
484
485 \section1 Scroll bars
486
487 \l QScrollBar draws \c CC_ScrollBar with a \l QStyleOptionSlider. While the
488 user drags the slider, the bar snaps the value back if the pointer moves
489 farther than \c PM_MaximumDragDistance outside the bar.
490
491 \list
492 \li \c CC_ScrollBar (\c PM_ScrollBarExtent, \c PM_ScrollBarSliderMin)
493 \list
494 \li \c SC_ScrollBarGroove
495 \li \c SC_ScrollBarSubLine (\c CE_ScrollBarSubLine)
496 \li \c SC_ScrollBarAddLine (\c CE_ScrollBarAddLine)
497 \li \c SC_ScrollBarSubPage (\c CE_ScrollBarSubPage)
498 \li \c SC_ScrollBarAddPage (\c CE_ScrollBarAddPage)
499 \li \c SC_ScrollBarFirst (\c CE_ScrollBarFirst)
500 \li \c SC_ScrollBarLast (\c CE_ScrollBarLast)
501 \li \c SC_ScrollBarSlider (\c CE_ScrollBarSlider)
502 \li \c PE_FrameFocusRect
503 \endlist
504 \endlist
505
506 \l QCommonStyle draws each subcontrol with the control element of the same
507 name. Some styles draw the line indicators with \c PE_IndicatorArrowUp and
508 the other arrow primitives, and the page areas with \c PE_PanelButtonBevel;
509 that is up to the individual style. \c SC_ScrollBarFirst and
510 \c SC_ScrollBarLast are optional buttons that jump to the ends; most styles
511 return an empty rectangle for them. The size hint uses \c CT_ScrollBar, and
512 behavior hints include \c SH_ScrollBar_LeftClickAbsolutePosition,
513 \c SH_ScrollBar_ContextMenu, and \c SH_ScrollBar_Transient.
514
515 \image styles/scrollbar.webp
516 {Horizontal scroll bar with the groove, line buttons, page areas, and
517 slider subcontrols outlined}
518
519 \l QScrollBar sets these state flags:
520
521 \table 90%
522 \header
523 \li State
524 \li Set when
525 \row
526 \li \c State_Horizontal
527 \li The scroll bar is horizontal.
528 \row
529 \li \c State_Sunken
530 \li A subcontrol is pressed and the pointer hasn't left it.
531 \row
532 \li \c State_On
533 \li The bar is a transient scroll bar that is currently shown.
534 \endtable
535
536 The members of \l QStyleOptionSlider are listed under \l{Sliders}.
537 \c sliderPosition, \c sliderValue, \c pageStep, and \c upsideDown decide the
538 size and position of the handle.
539
540 \section1 Progress bars
541
542 \l QProgressBar draws one control element, \c CE_ProgressBar, with a
543 \l QStyleOptionProgressBar. \l QCommonStyle splits it into the groove, the
544 contents, and the label:
545
546 \list
547 \li \c CE_ProgressBar
548 \list
549 \li \c CE_ProgressBarGroove (\c SE_ProgressBarGroove)
550 \li \c CE_ProgressBarContents (\c SE_ProgressBarContents,
551 \c PM_ProgressBarChunkWidth)
552 \li \c CE_ProgressBarLabel (\c SE_ProgressBarLabel)
553 \endlist
554 \endlist
555
556 Styles that draw the contents as a row of chunks use
557 \c PE_IndicatorProgressChunk. In \l QCommonStyle and Fusion, the groove, the
558 contents, and the label all get the whole bar; the label is centered text
559 drawn over the contents, so its rectangle isn't a separate area. The size
560 hint uses \c CT_ProgressBar. A busy indicator, a bar whose minimum and
561 maximum are both zero, is animated by the style.
562
563 \image styles/progressbar.webp
564 {Progress bar at 40% with the groove, contents, and label outlined}
565
566 \l QProgressBar sets this state flag:
567
568 \table 90%
569 \header
570 \li State
571 \li Set when
572 \row
573 \li \c State_Horizontal
574 \li The bar is horizontal.
575 \endtable
576
577 The other members of \l QStyleOptionProgressBar are:
578
579 \table 90%
580 \header
581 \li Member
582 \li Description
583 \row
584 \li minimum
585 \li The minimum value.
586 \row
587 \li maximum
588 \li The maximum value.
589 \row
590 \li progress
591 \li The current value.
592 \row
593 \li text
594 \li The label text.
595 \row
596 \li textAlignment
597 \li The alignment of the text in the label.
598 \row
599 \li textVisible
600 \li Whether the label is drawn.
601 \row
602 \li invertedAppearance
603 \li Whether the bar fills from the opposite end, for example, from
604 right to left in a horizontal bar.
605 \row
606 \li bottomToTop
607 \li Whether the label of a vertical bar is rotated to read from
608 bottom to top.
609 \endtable
610
611 \sa {Widget Style Reference}, {Styling Containers and Windows},
612 {Styling Menus and Item Views}
613*/