The QStyle class specifies the look and feel of a GUI.
A large number of GUI elements are common to many widgets. The
QStyle class allows the look of these elements to be modified
across all widgets that use the QStyle functions. It also
provides two feel options: Motif and Windows.
Although it is not possible to fully enumerate the look of
graphical elements and the feel of widgets in a GUI, QStyle
provides a considerable amount of control and customisability.
In Qt 1.x the look and feel option for widgets was specified by a
single value: the GUIStyle. Starting with Qt 2.0, this notion was
expanded to allow the look to be specified by virtual drawing
functions.
Derived classes may reimplement some or all of the drawing
functions to modify the look of all widgets that use those
functions.
Languages written from right to left (such as Arabic and Hebrew)
usually also mirror the whole layout of widgets. If you design a
style, you should take special care when drawing asymmetric
elements to make sure that they also look correct in a mirrored
layout. You can start your application with -reverse to check
the mirrored layout. Also notice, that for a reversed layout, the
light usually comes from top right instead of top left.
The actual reverse layout is performed automatically when
possible. However, for the sake of flexibility, the translation
cannot be performed everywhere. The documentation for each
function in the QStyle API states whether the function
expects/returns logical or screen coordinates. Using logical
coordinates (in ComplexControls, for example) provides great
flexibility in controlling the look of a widget. Use visualRect()
when necessary to translate logical coordinates into screen
coordinates for drawing.
In Qt versions prior to 3.0, if you wanted a low level route into
changing the appearance of a widget, you would reimplement
polish(). With the new 3.0 style engine the recommended approach
is to reimplement the draw functions, for example drawItem(),
drawPrimitive(), drawControl(), drawControlMask(),
drawComplexControl() and drawComplexControlMask(). Each of these
functions is called with a range of parameters that provide
information that you can use to determine how to draw them, e.g.
style flags, rectangle, color group, etc.
For information on changing elements of an existing style or
creating your own style see the Style
overview.
This enum represents a ComplexControl. ComplexControls have
different behaviour depending upon where the user clicks on them
or which keys are pressed.
QStyle::CC_SpinWidget
QStyle::CC_ComboBox
QStyle::CC_ScrollBar
QStyle::CC_Slider
QStyle::CC_ToolButton
QStyle::CC_TitleBar
QStyle::CC_ListView
QStyle::CC_CustomBase - base value for custom ControlElements. All
values above this are reserved for custom use. Therefore,
custom values must be greater than this value.
This enum represents a ContentsType. It is used to calculate sizes
for the contents of various widgets.
QStyle::CT_PushButton
QStyle::CT_CheckBox
QStyle::CT_RadioButton
QStyle::CT_ToolButton
QStyle::CT_ComboBox
QStyle::CT_Splitter
QStyle::CT_DockWindow
QStyle::CT_ProgressBar
QStyle::CT_PopupMenuItem
QStyle::CT_CustomBase - base value for custom ControlElements. All
values above this are reserved for custom use. Therefore,
custom values must be greater than this value.
This enum represents a ControlElement. A ControlElement is part of
a widget that performs some action or displays information to the
user.
QStyle::CE_PushButton - the bevel and default indicator of a QPushButton.
QStyle::CE_PushButtonLabel - the label (iconset with text or pixmap)
of a QPushButton.
QStyle::CE_CheckBox - the indicator of a QCheckBox.
QStyle::CE_CheckBoxLabel - the label (text or pixmap) of a QCheckBox.
QStyle::CE_RadioButton - the indicator of a QRadioButton.
QStyle::CE_RadioButtonLabel - the label (text or pixmap) of a QRadioButton.
QStyle::CE_TabBarTab - the tab within a QTabBar (a QTab).
QStyle::CE_TabBarLabel - the label within a QTab.
QStyle::CE_ProgressBarGroove - the groove where the progress
indicator is drawn in a QProgressBar.
QStyle::CE_ProgressBarContents - the progress indicator of a QProgressBar.
QStyle::CE_ProgressBarLabel - the text label of a QProgressBar.
QStyle::CE_PopupMenuItem - a menu item in a QPopupMenu.
QStyle::CE_PopupMenuScroller - scrolling areas in a popumenu when the
style supports scrolling.
QStyle::CE_MenuBarItem - a menu item in a QMenuBar.
QStyle::CE_ToolButtonLabel - a tool button's label.
QStyle::CE_CustomBase - base value for custom ControlElements. All values above
this are reserved for custom use. Therefore, custom values must be
greater than this value.
This enum represents a PixelMetric. A PixelMetric is a style
dependent size represented as a single pixel value.
QStyle::PM_ButtonMargin - amount of whitespace between pushbutton
labels and the frame.
QStyle::PM_ButtonDefaultIndicator - width of the default-button indicator frame.
QStyle::PM_MenuButtonIndicator - width of the menu button indicator
proportional to the widget height.
QStyle::PM_ButtonShiftHorizontal - horizontal contents shift of a
button when the button is down.
QStyle::PM_ButtonShiftVertical - vertical contents shift of a button when the
button is down.
QStyle::PM_DefaultFrameWidth - default frame width, usually 2.
QStyle::PM_SpinBoxFrameWidth - frame width of a spin box.
QStyle::PM_MaximumDragDistance - Some feels require the scrollbar or
other sliders to jump back to the original position when the
mouse pointer is too far away while dragging. A value of -1
disables this behavior.
QStyle::PM_ScrollBarExtent - width of a vertical scrollbar and the
height of a horizontal scrollbar.
QStyle::PM_ScrollBarSliderMin - the minimum height of a vertical
scrollbar's slider and the minimum width of a horiztonal
scrollbar slider.
QStyle::PM_SliderThickness - total slider thickness.
QStyle::PM_SliderControlThickness - thickness of the slider handle.
QStyle::PM_SliderLength - length of the slider.
QStyle::PM_SliderTickmarkOffset - the offset between the tickmarks
and the slider.
QStyle::PM_SliderSpaceAvailable - the available space for the slider to move.
QStyle::PM_DockWindowSeparatorExtent - width of a separator in a
horiztonal dock window and the height of a separator in a
vertical dock window.
QStyle::PM_DockWindowHandleExtent - width of the handle in a
horizontal dock window and the height of the handle in a
vertical dock window.
QStyle::PM_DockWindowFrameWidth - frame width of a dock window.
QStyle::PM_MenuBarFrameWidth - frame width of a menubar.
QStyle::PM_TabBarTabOverlap - number of pixels the tabs should overlap.
QStyle::PM_TabBarTabHSpace - extra space added to the tab width.
QStyle::PM_TabBarTabVSpace - extra space added to the tab height.
QStyle::PM_TabBarBaseHeight - height of the area between the tab bar
and the tab pages.
QStyle::PM_TabBarBaseOverlap - number of pixels the tab bar overlaps
the tab bar base.
QStyle::PM_ProgressBarChunkWidth - width of a chunk in a progress bar indicator.
QStyle::PM_SplitterWidth - width of a splitter.
QStyle::PM_TitleBarHeight - height of the title bar.
QStyle::PM_IndicatorWidth - width of a check box indicator.
QStyle::PM_IndicatorHeight - height of a checkbox indicator.
QStyle::PM_ExclusiveIndicatorWidth - width of a radio button indicator.
QStyle::PM_ExclusiveIndicatorHeight - height of a radio button indicator.
QStyle::PM_PopupMenuScrollerHeight - height of the scroller area in a popupmenu.
QStyle::PM_CustomBase - base value for custom ControlElements. All
values above this are reserved for custom use. Therefore,
custom values must be greater than this value.
QStyle::PE_ScrollBarFirst - scrollbar first line indicator (i.e. home).
QStyle::PE_ScrollBarLast - scrollbar last line indicator (i.e. end).
QStyle::PE_ProgressBarChunk - section of a progress bar indicator; see
also QProgressBar.
QStyle::PE_CustomBase - base value for custom ControlElements. All values above
this are reserved for custom use. Therefore, custom values must be
greater than this value.
This enum represents flags for drawing PrimitiveElements. Not all
primitives use all of these flags. Note that these flags may mean
different things to different primitives. For an explanation of
the relationship between primitives and their flags, as well as
the different meanings of the flags, see the Style overview.
This enum represents a StyleHint. A StyleHint is a general look
and/or feel hint.
QStyle::SH_EtchDisabledText - disabled text is "etched" like Windows.
QStyle::SH_GUIStyle - the GUI style to use.
QStyle::SH_ScrollBar_BackgroundMode - the background mode for a
QScrollBar. Possible values are any of those in the BackgroundMode enum.
QStyle::SH_ScrollBar_MiddleClickAbsolutePosition - a boolean value.
If TRUE, middle clicking on a scrollbar causes the slider to
jump to that position. If FALSE, the middle clicking is
ignored.
QStyle::SH_ScrollBar_ScrollWhenPointerLeavesControl - a boolean
value. If TRUE, when clicking a scrollbar SubControl, holding
the mouse button down and moving the pointer outside the
SubControl, the scrollbar continues to scroll. If FALSE, the
scollbar stops scrolling when the pointer leaves the
SubControl.
QStyle::SH_Header_ArrowAlignment - the placement of the sorting
indicator may appear in list or table headers. Possible values
are Qt::Left or Qt::Right.
QStyle::SH_Slider_SnapToValue - sliders snap to values while moving,
like Windows
QStyle::SH_Slider_SloppyKeyEvents - key presses handled in a sloppy
manner, i.e. left on a vertical slider subtracts a line.
QStyle::SH_ProgressDialog_CenterCancelButton - center button on
progress dialogs, like Motif, otherwise right aligned.
QStyle::SH_ProgressDialog_TextLabelAlignment - Qt::AlignmentFlags --
text label alignment in progress dialogs; Center on windows,
Auto|VCenter otherwise.
QStyle::SH_PrintDialog_RightAlignButtons - right align buttons in
the print dialog, like Windows.
QStyle::SH_MainWindow_SpaceBelowMenuBar - 1 or 2 pixel space between
the menubar and the dockarea, like Windows.
QStyle::SH_FontDialog_SelectAssociatedText - select the text in the
line edit, or when selecting an item from the listbox, or when
the line edit receives focus, like Windows.
QStyle::SH_PopupMenu_AllowActiveAndDisabled - allows disabled menu
items to be active.
QStyle::SH_PopupMenu_SpaceActivatesItem - pressing Space activates
the item, like Motif.
QStyle::SH_PopupMenu_SubMenuPopupDelay - the number of milliseconds
to wait before opening a submenu; 256 on windows, 96 on Motif.
QStyle::SH_ScrollView_FrameOnlyAroundContents - whether scrollviews
draw their frame only around contents (like Motif), or around
contents, scrollbars and corner widgets (like Windows).
QStyle::SH_MenuBar_AltKeyNavigation - menubars items are navigable
by pressing Alt, followed by using the arrow keys to select
the desired item.
QStyle::SH_ComboBox_ListMouseTracking - mouse tracking in combobox
dropdown lists.
QStyle::SH_PopupMenu_MouseTracking - mouse tracking in popup menus.
QStyle::SH_MenuBar_MouseTracking - mouse tracking in menubars.
QStyle::SH_ItemView_ChangeHighlightOnFocus - gray out selected items
when losing focus.
QStyle::SH_Widget_ShareActivation - turn on sharing activation with
floating modeless dialogs.
QStyle::SH_TabBar_SelectMouseType - which type of mouse event should
cause a tab to be selected.
QStyle::SH_ComboBox_Popup - allows popups as a combobox dropdown
menu.
QStyle::SH_Workspace_FillSpaceOnMaximize - the workspace should
maximize the client area.
QStyle::SH_TitleBar_NoBorder - the titlebar has no border
QStyle::SH_ScrollBar_StopMouseOverSlider - stops autorepeat when
slider reaches mouse
QStyle::SH_BlinkCursorWhenTextSelected - whether cursor should blink
when text is selected
QStyle::SH_RichText_FullWidthSelection - whether richtext selections
should extend the full width of the document.
QStyle::SH_PopupMenu_Scrollable - whether popupmenu's must support
scrolling.
QStyle::SH_CustomBase - base value for custom ControlElements. All
values above this are reserved for custom use. Therefore,
custom values must be greater than this value.
This enum represents a StylePixmap. A StylePixmap is a pixmap that
can follow some existing GUI style or guideline.
QStyle::SP_TitleBarMinButton - minimize button on titlebars. For
example, in a QWorkspace.
QStyle::SP_TitleBarMaxButton - maximize button on titlebars.
QStyle::SP_TitleBarCloseButton - close button on titlebars.
QStyle::SP_TitleBarNormalButton - normal (restore) button on titlebars.
QStyle::SP_TitleBarShadeButton - shade button on titlebars.
QStyle::SP_TitleBarUnshadeButton - unshade button on titlebars.
QStyle::SP_MessageBoxInformation - the 'information' icon.
QStyle::SP_MessageBoxWarning - the 'warning' icon.
QStyle::SP_MessageBoxCritical - the 'critical' icon.
QStyle::SP_DockWindowCloseButton - close button on dock windows;
see also QDockWindow.
QStyle::SP_CustomBase - base value for custom ControlElements. All
values above this are reserved for custom use. Therefore,
custom values must be greater than this value.
This enum represents a sub-area of a widget. Style implementations
would use these areas to draw the different parts of a widget.
QStyle::SR_PushButtonContents - area containing the label (iconset
with text or pixmap).
QStyle::SR_PushButtonFocusRect - area for the focus rect (usually
larger than the contents rect).
QStyle::SR_CheckBoxIndicator - area for the state indicator (e.g. check mark).
QStyle::SR_CheckBoxContents - area for the label (text or pixmap).
QStyle::SR_CheckBoxFocusRect - area for the focus indicator.
QStyle::SR_RadioButtonIndicator - area for the state indicator.
QStyle::SR_RadioButtonContents - area for the label.
QStyle::SR_RadioButtonFocusRect - area for the focus indicator.
QStyle::SR_ComboBoxFocusRect - area for the focus indicator.
QStyle::SR_SliderFocusRect - area for the focus indicator.
QStyle::SR_DockWindowHandleRect - area for the tear-off handle.
QStyle::SR_ProgressBarGroove - area for the groove.
QStyle::SR_ProgressBarContents - area for the progress indicator.
QStyle::SR_ProgressBarLabel - area for the text label.
QStyle::SR_ToolButtonContents - area for the tool button's label.
QStyle::SR_CustomBase - base value for custom ControlElements. All values above
this are reserved for custom use. Therefore, custom values must be
greater than this value.
Draws the ComplexControl control using the painter p in the
area r. Colors are used from the color group cg. The sub
argument specifies which SubControls to draw. Multiple SubControls
can be OR'ed together. The subActive argument specifies which
SubControl is active.
The rect r should be in logical coordinates. Reimplementations
of this function should use visualRect() to change the logical
coordinates into screen coordinates when using drawPrimitive() and
drawControl().
The how argument is used to control how the ComplexControl is
drawn. Multiple flags can OR'ed together. See the table below for
an explanation of which flags are used with the various
ComplexControls.
The widget argument is a pointer to a QWidget or one of its
subclasses. The widget can be cast to the appropriate type based
on the value of control. The opt argument can be used to
pass extra information required when drawing the ComplexControl.
Note that opt may be the default value even for ComplexControls
that can make use of the extra options. See the table below for
the appropriate widget and opt usage:
Draw a bitmask for the ComplexControl control using the painter
p in the area r. See drawComplexControl() for an explanation
of the use of the widget and opt arguments.
The rect r should be in logical coordinates. Reimplementations
of this function should use visualRect() to change the logical
corrdinates into screen coordinates when using drawPrimitive() and
drawControl().
Draws the ControlElement element using the painter p in the
area r. Colors are used from the color group cg.
The rect r should be in screen coordinates.
The how argument is used to control how the ControlElement is
drawn. Multiple flags can be OR'ed together. See the table below
for an explanation of which flags are used with the various
ControlElements.
The widget argument is a pointer to a QWidget or one of its
subclasses. The widget can be cast to the appropriate type based
on the value of element. The opt argument can be used to
pass extra information required when drawing the ControlElement.
Note that opt may be the default value even for ControlElements
that can make use of the extra options. See the table below for
the appropriate widget and opt usage:
Draw a bitmask for the ControlElement element using the painter
p in the area r. See drawControl() for an explanation of the
use of the widget and opt arguments.
Draws the text or pixmap in rectangle r using painter p and color group g. The pen color is specified with penColor. The enabled bool indicates whether or not the item is
enabled; when reimplementing this bool should influence how the
item is drawn. If len is -1 (the default) all the text is
drawn; otherwise only the first len characters of text are
drawn. The text is aligned and wrapped according to the alignment
flags (see Qt::AlignmentFlags).
By default, if both the text and the pixmap are not null, the
pixmap is drawn and the text is ignored.
The opt argument can be used to control how various
PrimitiveElements are drawn. Note that opt may be the default
value even for PrimitiveElements that make use of extra options.
When opt is non-default, it is used as follows:
QRectQStyle::itemRect ( QPainter * p, const QRect & r, int flags, bool enabled, const QPixmap * pixmap, const QString & text, int len = -1 ) const [virtual]
Returns the appropriate area (see below) within rectangle r in
which to draw the text or pixmap using painter p. If len is -1 (the default) all the text is drawn; otherwise only
the first len characters of text are drawn. The text is
aligned in accordance with the alignment flags (see
Qt::AlignmentFlags). The enabled bool indicates whether or
not the item is enabled.
If r is larger than the area needed to render the text the
rectangle that is returned will be offset within r in
accordance with the alignment flags. For example if flags is
AlignCenter the returned rectangle will be centered within r. If r is smaller than the area needed the rectangle that is
returned will be larger than r (the smallest rectangle large
enough to render the text or pixmap).
By default, if both the text and the pixmap are not null, the
pixmap is drawn and the text is ignored.
Returns the pixel metric for metric. The widget argument is
a pointer to a QWidget or one of its subclasses. The widget can be
cast to the appropriate type based on the value of metric. Note
that widget may be zero even for PixelMetrics that can make use
of widget. See the table below for the appropriate widget
casts:
This function is called for every widget at some point after it
has been fully created but just before it is shown the very
first time.
Reasonable actions in this function might be to call
QWidget::setBackgroundMode() for the widget. An example of highly
unreasonable use would be setting the geometry! Reimplementing
this function gives you a back-door through which you can change
the appearance of a widget. With Qt 3.0's style engine you will
rarely need to write your own polish(); instead reimplement
drawItem(), drawPrimitive(), etc.
The QWidget::inherits() function may provide enough information to
allow class-specific customizations. But be careful not to
hard-code things too much because new QStyle subclasses are
expected to work reasonably with all current and future
widgets.
Returns the SubControl for widget at the point pos. The widget argument is a pointer to a QWidget or one of its
subclasses. The widget can be cast to the appropriate type based
on the value of control. The opt argument can be used to
pass extra information required when drawing the ComplexControl.
Note that opt may be the default value even for ComplexControls
that can make use of the extra options. See drawComplexControl()
for an explanation of the widget and opt arguments.
Note that pos is passed in screen coordinates. When using
querySubControlMetrics() to check for hits and misses, use
visualRect() to change the logical coordinates into screen
coordinates.
Returns the rect for the SubControl subcontrol for widget in
logical coordinates.
The widget argument is a pointer to a QWidget or one of its
subclasses. The widget can be cast to the appropriate type based
on the value of control. The opt argument can be used to
pass extra information required when drawing the ComplexControl.
Note that opt may be the default value even for ComplexControls
that can make use of the extra options. See drawComplexControl()
for an explanation of the widget and opt arguments.
Returns the size of widget based on the contents size contentsSize.
The widget argument is a pointer to a QWidget or one of its
subclasses. The widget can be cast to the appropriate type based
on the value of contents. The opt argument can be used to
pass extra information required when calculating the size. Note
that opt may be the default value even for ContentsTypes that
can make use of the extra options. See the table below for the
appropriate widget and opt usage:
The opt argument can be used to pass extra information required
when drawing the ControlElement. Note that opt may be the
default value even for StylePixmaps that can make use of the extra
options. Currently, the opt argument is unused.
The widget argument is a pointer to a QWidget or one of its
subclasses. The widget can be cast to the appropriate type based
on the value of stylepixmap. See the table below for the
appropriate widget casts:
Returns the sub-area subrect for the widget in logical
coordinates.
The widget argument is a pointer to a QWidget or one of its
subclasses. The widget can be cast to the appropriate type based
on the value of subrect. See the table below for the
appropriate widget casts:
Undoes the initialization of a widget's appearance.
This function is the counterpart to polish. It is called for every
polished widget when the style is dynamically changed. The former
style has to unpolish its settings before the new style can polish
them again.
Returns the rect logical in screen coordinates. The bounding
rect for widget w is used to perform the translation. This
function is provided to aid style implementors in supporting
right-to-left mode.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns the rect logical in screen coordinates. The rect bounding is used to perform the translation. This function is
provided to aid style implementors in supporting right-to-left
mode.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter
ou par MP !