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-containers.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-containers.html
6 \title Styling Containers and Windows
7 \brief The style elements, states, and options of tab widgets, group boxes,
8 splitters, toolboxes, toolbars, dock widgets, title bars, size grips, and
9 rubber bands.
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 Tab widgets and tab bars
18
19 \l QTabBar draws its tabs through the style. A tab bar is either part of a
20 \l QTabWidget or standalone. A standalone bar draws its own base line. In a
21 tab widget, the widget draws the frame around the pane and the bar sits on
22 top of it.
23
24 \l QTabWidget draws \c PE_FrameTabWidget with a
25 \l QStyleOptionTabWidgetFrame. It asks the style where to put the tab bar,
26 the pane, the contents, and the corner widgets with \c SE_TabWidgetTabPane,
27 \c SE_TabWidgetTabContents, \c SE_TabWidgetTabBar,
28 \c SE_TabWidgetLeftCorner, and \c SE_TabWidgetRightCorner, and it overlaps
29 the bar and the pane by \c PM_TabBarBaseOverlap.
30
31 \l QTabBar lays out the tabs itself, so the style has no control over tab
32 placement. While laying out, the bar asks for \c CT_TabBarTab, which
33 includes \c PM_TabBarTabHSpace and \c PM_TabBarTabVSpace, the extra width
34 and height around the label. It then draws each tab with \c CE_TabBarTab and
35 a \l QStyleOptionTab. The selected tab is drawn last so that a style can
36 draw it over its neighbors.
37
38 \list
39 \li \c PE_FrameTabBarBase (\c PM_TabBarBaseHeight, \c PM_TabBarBaseOverlap),
40 for a standalone bar, with a \l QStyleOptionTabBarBase
41 \li \c CE_TabBarTab, once per tab
42 \list
43 \li \c CE_TabBarTabShape (\c PM_TabBarTabOverlap)
44 \li \c CE_TabBarTabLabel (\c SE_TabBarTabText,
45 \c SE_TabBarTabLeftButton, \c SE_TabBarTabRightButton,
46 \c PM_TabBarTabShiftHorizontal, \c PM_TabBarTabShiftVertical,
47 \c PM_TabBarIconSize)
48 \endlist
49 \li \c PE_IndicatorTabClose, drawn by the close button of a closable tab
50 (\c SH_TabBar_CloseButtonPosition, \c PM_TabCloseIndicatorWidth,
51 \c PM_TabCloseIndicatorHeight)
52 \li \c PE_IndicatorTabTearLeft and \c PE_IndicatorTabTearRight, where tabs
53 are cut off by the scroll buttons (\c SE_TabBarTearIndicatorLeft,
54 \c SE_TabBarTearIndicatorRight)
55 \endlist
56
57 The scroll buttons that appear when the tabs don't fit are
58 \l{QToolButton}{tool buttons}; the style places them with
59 \c SE_TabBarScrollLeftButton and \c SE_TabBarScrollRightButton and sizes
60 them with \c PM_TabBarScrollButtonWidth. The bar also consults
61 \c SH_TabBar_Alignment, \c SH_TabBar_ElideMode, and
62 \c SH_TabBar_PreferNoArrows.
63
64 \image styles/tabwidget.webp
65 {Tab widget with three tabs and a corner button, with the pane,
66 contents, tab bar, corner, tab, and tab label rectangles outlined}
67
68 \l QTabBar sets these state flags on each tab:
69
70 \table 90%
71 \header
72 \li State
73 \li Set when
74 \row
75 \li \c State_Sunken
76 \li The tab is pressed.
77 \row
78 \li \c State_Selected
79 \li The tab is the current tab.
80 \row
81 \li \c State_HasFocus
82 \li The tab bar has focus and the tab is selected.
83 \row
84 \li \c State_MouseOver
85 \li The mouse is over the tab.
86 \endtable
87
88 Individual tabs can be disabled even when the tab bar is enabled. The tab is
89 active when the tab bar is active. The members of \l QStyleOptionTab are:
90
91 \table 90%
92 \header
93 \li Member
94 \li Description
95 \row
96 \li shape
97 \li A \l QTabBar::Shape value: rounded or triangular tabs, and the
98 side of the widget the bar is on.
99 \row
100 \li text
101 \li The tab text.
102 \row
103 \li icon
104 \li The tab icon.
105 \row
106 \li iconSize
107 \li The size of the icon.
108 \row
109 \li row
110 \li The row the tab is in. Qt's tab bars have one row.
111 \row
112 \li position
113 \li A \l{QStyleOptionTab::}{TabPosition} value: the tab's position
114 relative to the other tabs, or \c Moving while the user drags
115 it.
116 \row
117 \li selectedPosition
118 \li A \l{QStyleOptionTab::}{SelectedPosition} value that tells
119 whether the selected tab is next to this tab, and on which side.
120 \row
121 \li cornerWidgets
122 \li Flags of the \l{QStyleOptionTab::}{CornerWidget} enum that tell
123 which corner widgets the tab bar has.
124 \row
125 \li documentMode
126 \li Whether the tab bar is in
127 \l{QTabBar::documentMode}{document mode}.
128 \row
129 \li leftButtonSize, rightButtonSize
130 \li The sizes of the buttons on the left and right side of the tab,
131 such as the close button.
132 \row
133 \li features
134 \li Flags of the \l{QStyleOptionTab::}{TabFeature} enum: whether the
135 tab has a frame and whether it uses its minimum size hint.
136 \row
137 \li tabIndex
138 \li The index of the tab in the bar.
139 \endtable
140
141 The members of \l QStyleOptionTabWidgetFrame are:
142
143 \table 90%
144 \header
145 \li Member
146 \li Description
147 \row
148 \li lineWidth
149 \li The line width for drawing the panel.
150 \row
151 \li midLineWidth
152 \li Always 0.
153 \row
154 \li shape
155 \li The shape of the tabs on the tab bar.
156 \row
157 \li tabBarSize
158 \li The size of the tab bar.
159 \row
160 \li tabBarRect
161 \li The rectangle of the tab bar.
162 \row
163 \li selectedTabRect
164 \li The rectangle of the selected tab, so that the frame can connect
165 to it.
166 \row
167 \li leftCornerWidgetSize, rightCornerWidgetSize
168 \li The sizes of the corner widgets, if any.
169 \endtable
170
171 \l QStyleOptionTabBarBase, used for \c PE_FrameTabBarBase, has the members
172 \c shape, \c tabBarRect, \c selectedTabRect, and \c documentMode with the
173 same meaning.
174
175 \section1 Group boxes
176
177 \l QGroupBox draws one complex control, \c CC_GroupBox, with a
178 \l QStyleOptionGroupBox. It calculates its size hint from
179 \c PM_IndicatorWidth, \c PM_IndicatorHeight, and \c PM_CheckBoxLabelSpacing.
180
181 \list
182 \li \c CC_GroupBox
183 \list
184 \li \c SC_GroupBoxFrame (\c PE_FrameGroupBox)
185 \li \c SC_GroupBoxLabel, drawn with \l{QStyle::}{drawItemText()}, plus
186 \c PE_FrameFocusRect when the box has focus
187 \li \c SC_GroupBoxCheckBox (\c PE_IndicatorCheckBox), for a checkable
188 box
189 \li \c SC_GroupBoxContents, the area for the child widgets
190 \endlist
191 \endlist
192
193 The style hints \c SH_GroupBox_TextLabelVerticalAlignment and
194 \c SH_GroupBox_TextLabelColor control the title. Qt doesn't dictate how the
195 checkbox is drawn; \l QCommonStyle uses \c PE_IndicatorCheckBox, so the
196 element tree under
197 \l{Styling Buttons and Input Widgets#Checkboxes and radio buttons}
198 {Checkboxes and radio buttons} applies.
199
200 \image styles/groupbox.webp
201 {Checkable group box with two checkboxes inside, with the frame,
202 checkbox, label, and contents subcontrols outlined}
203
204 \l QGroupBox sets these state flags:
205
206 \table 90%
207 \header
208 \li State
209 \li Set when
210 \row
211 \li \c State_On
212 \li The checkbox is checked.
213 \row
214 \li \c State_Off
215 \li The checkbox is unchecked. A group box that isn't checkable sets
216 neither \c State_On nor \c State_Off.
217 \row
218 \li \c State_Sunken
219 \li The checkbox or the title label is pressed.
220 \endtable
221
222 The other members of \l QStyleOptionGroupBox are:
223
224 \table 90%
225 \header
226 \li Member
227 \li Description
228 \row
229 \li features
230 \li \l QStyleOptionFrame::FrameFeatures flags that describe the
231 frame, such as \c Flat for a flat group box.
232 \row
233 \li lineWidth
234 \li The line width of the frame. Always 1.
235 \row
236 \li midLineWidth
237 \li Always 0.
238 \row
239 \li text
240 \li The title.
241 \row
242 \li textAlignment
243 \li The alignment of the title.
244 \row
245 \li textColor
246 \li The \c SH_GroupBox_TextLabelColor value. The group box only
247 fills it in when the application hasn't set a \c WindowText
248 brush in the palette; otherwise it stays invalid and
249 \l QCommonStyle uses the palette instead.
250 \endtable
251
252 \section1 Splitters
253
254 \l QSplitterHandle draws one control element, \c CE_Splitter, with a plain
255 \l QStyleOption. The splitter sizes its handles with \c CT_Splitter and
256 \c PM_SplitterWidth and asks for \c SH_Splitter_OpaqueResize to decide
257 whether to resize the children while the user drags.
258
259 \image styles/splitter.webp
260 {Splitter with three text panes and the two handles outlined}
261
262 The handle fills in the option itself rather than calling
263 \l{QStyleOption::}{initFrom()}. It sets these state flags:
264
265 \table 90%
266 \header
267 \li State
268 \li Set when
269 \row
270 \li \c State_Horizontal
271 \li The splitter is horizontal, so the handle is vertical.
272 \row
273 \li \c State_MouseOver
274 \li The mouse is over the handle.
275 \row
276 \li \c State_Sunken
277 \li The handle is pressed.
278 \row
279 \li \c State_Enabled
280 \li The handle is enabled.
281 \endtable
282
283 \section1 Toolboxes
284
285 \l QToolBox keeps a collection of widgets and shows one at a time, with one
286 tab button per widget in a vertical layout. Each button draws
287 \c CE_ToolBoxTab with a \l QStyleOptionToolBox, and the buttons use
288 \c PM_SmallIconSize for their icons.
289
290 \list
291 \li \c CE_ToolBoxTab, once per page
292 \list
293 \li \c CE_ToolBoxTabShape
294 \li \c CE_ToolBoxTabLabel (\c SE_ToolBoxTabContents)
295 \endlist
296 \endlist
297
298 \image styles/toolbox.webp
299 {Toolbox with three tabs and the first page open, with the tabs and
300 the current page outlined}
301
302 The tab button sets these state flags:
303
304 \table 90%
305 \header
306 \li State
307 \li Set when
308 \row
309 \li \c State_Selected
310 \li The tab is the current tab.
311 \row
312 \li \c State_Sunken
313 \li The tab is pressed.
314 \endtable
315
316 The other members of \l QStyleOptionToolBox are:
317
318 \table 90%
319 \header
320 \li Member
321 \li Description
322 \row
323 \li icon
324 \li The icon on the tab.
325 \row
326 \li text
327 \li The text on the tab.
328 \row
329 \li position
330 \li A \l{QStyleOptionToolBox::}{TabPosition} value: the tab's
331 position relative to the other tabs.
332 \row
333 \li selectedPosition
334 \li A \l{QStyleOptionToolBox::}{SelectedPosition} value that tells
335 whether the selected tab is next to this tab, and on which side.
336 \endtable
337
338 \section1 Toolbars
339
340 Toolbars are part of the \l{QMainWindow}{main window framework}. A main
341 window has four toolbar areas, one along each side, and each area can hold
342 several lines of toolbars. \l QMainWindow positions the toolbars and fills
343 in the position members of their style option.
344
345 \l QToolBar draws \c CE_ToolBar with a \l QStyleOptionToolBar. When the
346 toolbar floats in its own window, it also draws \c PE_FrameMenu around it. A
347 movable toolbar draws its handle, and the separators between actions are
348 small widgets that draw \c PE_IndicatorToolBarSeparator.
349
350 \list
351 \li \c CE_ToolBar (\c PM_ToolBarFrameWidth, \c PM_ToolBarItemMargin,
352 \c PM_ToolBarItemSpacing)
353 \list
354 \li \c PE_PanelToolBar
355 \endlist
356 \li \c PE_FrameMenu, for a floating toolbar
357 \li \c PE_IndicatorToolBarHandle (\c SE_ToolBarHandle,
358 \c PM_ToolBarHandleExtent)
359 \li \c PE_IndicatorToolBarSeparator (\c PM_ToolBarSeparatorExtent), drawn by
360 each separator
361 \endlist
362
363 The tool buttons in the bar draw \c CC_ToolButton; see
364 \l{Styling Buttons and Input Widgets#Tool buttons}{Tool buttons}. Their icon
365 size defaults to \c PM_ToolBarIconSize. When the actions don't fit, the bar
366 shows an extension button with the \c SP_ToolBarHorizontalExtensionButton or
367 \c SP_ToolBarVerticalExtensionButton icon, sized by
368 \c PM_ToolBarExtensionExtent.
369
370 \image styles/toolbar.webp
371 {Toolbar with a handle, three tool buttons, and a separator, with
372 each element outlined}
373
374 \l QToolBar sets this state flag:
375
376 \table 90%
377 \header
378 \li State
379 \li Set when
380 \row
381 \li \c State_Horizontal
382 \li The toolbar is horizontal, that is, in the top or bottom toolbar
383 area.
384 \endtable
385
386 The separators use a plain \l QStyleOption with \c State_Horizontal set when
387 the toolbar is horizontal. The other members of \l QStyleOptionToolBar are:
388
389 \table 90%
390 \header
391 \li Member
392 \li Description
393 \row
394 \li features
395 \li \l{QStyleOptionToolBar::}{ToolBarFeature} flags: \c Movable if
396 the toolbar can be moved.
397 \row
398 \li lineWidth
399 \li The width of the toolbar frame.
400 \row
401 \li midLineWidth
402 \li Always 0.
403 \row
404 \li positionOfLine
405 \li A \l{QStyleOptionToolBar::}{ToolBarPosition} value: the position
406 of the toolbar's line within its toolbar area.
407 \row
408 \li positionWithinLine
409 \li A \l{QStyleOptionToolBar::}{ToolBarPosition} value: the position
410 of the toolbar within its line.
411 \row
412 \li toolBarArea
413 \li The \l{Qt::ToolBarArea} the toolbar is in.
414 \endtable
415
416 \section1 Dock widgets
417
418 \l QDockWidget draws its title bar with \c CE_DockWidgetTitle and a
419 \l QStyleOptionDockWidget, unless the application installed a custom title
420 bar widget or the dock widget floats with native window decorations. A
421 floating dock widget without native decorations also draws
422 \c PE_FrameDockWidget. The float and close buttons are tool buttons that
423 draw \c PE_PanelButtonTool and show the \c SP_TitleBarNormalButton and
424 \c SP_TitleBarCloseButton icons.
425
426 \list
427 \li \c PE_FrameDockWidget (\c PM_DockWidgetFrameWidth), when floating
428 \li \c CE_DockWidgetTitle (\c SE_DockWidgetTitleBarText,
429 \c SE_DockWidgetIcon, \c PM_DockWidgetTitleMargin)
430 \li \c SE_DockWidgetFloatButton and \c SE_DockWidgetCloseButton
431 (\c PM_DockWidgetTitleBarButtonMargin), the button positions
432 \endlist
433
434 \l QMainWindow draws the separators between docked widgets with
435 \c PE_IndicatorDockWidgetResizeHandle, sized by
436 \c PM_DockWidgetSeparatorExtent. The hint \c SH_DockWidget_ButtonsHaveFrame
437 decides whether the title bar buttons have a frame.
438
439 \image styles/dockwidget.webp
440 {Main window with a dock widget on the right, with the title bar,
441 title text, float and close buttons, and the separator outlined}
442
443 The title bar option sets no state flags beyond the common ones. The members
444 of \l QStyleOptionDockWidget are:
445
446 \table 90%
447 \header
448 \li Member
449 \li Description
450 \row
451 \li title
452 \li The title text.
453 \row
454 \li closable
455 \li Whether the dock widget can be closed.
456 \row
457 \li movable
458 \li Whether the dock widget can be moved to another area.
459 \row
460 \li floatable
461 \li Whether the dock widget can float, that is, detach from its main
462 window.
463 \row
464 \li verticalTitleBar
465 \li Whether the title bar is drawn vertically along the left side.
466 \endtable
467
468 \section1 Title bars
469
470 The title bar complex control, \c CC_TitleBar, draws the title bars of the
471 subwindows in a \l QMdiArea. It consists of a window title and the system
472 menu, minimize, maximize, and close buttons. Some styles also provide
473 buttons for shading the window and for context-sensitive help.
474
475 \list
476 \li \c CC_TitleBar (\c PM_TitleBarHeight, \c PM_TitleBarButtonSize,
477 \c PM_TitleBarButtonIconSize)
478 \list
479 \li \c SC_TitleBarSysMenu
480 \li \c SC_TitleBarLabel
481 \li \c SC_TitleBarMinButton, \c SC_TitleBarMaxButton,
482 \c SC_TitleBarCloseButton, \c SC_TitleBarNormalButton
483 \li \c SC_TitleBarShadeButton, \c SC_TitleBarUnshadeButton,
484 \c SC_TitleBarContextHelpButton
485 \endlist
486 \endlist
487
488 \l QCommonStyle draws each button with \c PE_PanelButtonTool and the
489 matching standard icon, from \c SP_TitleBarMenuButton to
490 \c SP_TitleBarContextHelpButton. When a subwindow is maximized,
491 \l QMdiSubWindow moves its buttons into the menu bar of the main window and
492 draws them with \c CC_MdiControls and the subcontrols \c SC_MdiMinButton,
493 \c SC_MdiNormalButton, and \c SC_MdiCloseButton.
494
495 \image styles/titlebar.webp
496 {Title bar with an icon, the text Sub window, and minimize, maximize,
497 and close buttons, with each subcontrol outlined}
498
499 The members of \l QStyleOptionTitleBar are:
500
501 \table 90%
502 \header
503 \li Member
504 \li Description
505 \row
506 \li text
507 \li The title text.
508 \row
509 \li icon
510 \li The window icon.
511 \row
512 \li titleBarFlags
513 \li \l{Qt::WindowFlags} that tell which buttons the title bar has.
514 \row
515 \li titleBarState
516 \li The \l QWidget::windowState() of the window, which decides
517 whether the maximize or the restore button is shown.
518 \endtable
519
520 \section1 Size grips
521
522 \l QSizeGrip draws one control element, \c CE_SizeGrip, with a
523 \l QStyleOptionSizeGrip, and calculates its size hint with \c CT_SizeGrip.
524 \l QStatusBar shows a size grip in its corner by default.
525
526 \image styles/sizegrip.webp
527 {Status bar with the message Ready and the size grip in the corner
528 outlined}
529
530 The size grip sets no state flags beyond the common ones.
531 \l QStyleOptionSizeGrip has one member of its own:
532
533 \table 90%
534 \header
535 \li Member
536 \li Description
537 \row
538 \li corner
539 \li A \l{Qt::Corner} value: the corner of the window the grip is in.
540 \endtable
541
542 \section1 Rubber bands
543
544 \l QRubberBand draws one control element, \c CE_RubberBand, with a
545 \l QStyleOptionRubberBand. The style can shape the band through the
546 \c SH_RubberBand_Mask style hint.
547
548 \image styles/rubberband.webp
549 {List view with a translucent rubber band selection rectangle
550 outlined}
551
552 The band sets no state flags beyond the common ones. The members of
553 \l QStyleOptionRubberBand are:
554
555 \table 90%
556 \header
557 \li Member
558 \li Description
559 \row
560 \li shape
561 \li A \l QRubberBand::Shape value: a rectangle or a line.
562 \row
563 \li opaque
564 \li Whether the band must be drawn opaquely.
565 \endtable
566
567 \sa {Widget Style Reference}, {Styling Buttons and Input Widgets},
568 {Styling Menus and Item Views}
569*/