【QT】3 - [QStyle] Qt常用组件属性说明

来源:互联网 发布:js onmouseover 编辑:程序博客网 时间:2024/06/08 00:49

Widget

简单的中文翻译

How to Style

QAbstractScrollArea

支持盒子模型,所有QAbstractScrollArea的派生类,包括QTextEdit、所有的列表类,支持可滚动背景background-attachment属性。

Supports the box model.

All derivatives of QAbstractScrollArea, including QTextEdit, and QAbstractItemView (all item view classes), support scrollable backgrounds using background-attachment. Setting the background-attachment to fixed provides a background-image that does not scroll with the viewport. Setting the background-attachment to scroll, scrolls the background-image when the scroll bars move.

See Customizing QAbstractScrollArea for an example.

QCheckBox

多选框,支持盒子模型,选中状态可以使用::indicator 控制,默认的选中状态放在左上角。状态指示器和文本之间的空间可以使用spacing控制。

Supports the box model. The check indicator can be styled using the ::indicator subcontrol. By default, the indicator is placed in the Top Left corner of the Contents rectangle of the widget.

The spacing property specifies the spacing between the check indicator and the text.

See Customizing QCheckBox for an example.

QColumnView

列视图,收缩状态可以设置image属性,鼠标样式可以使用::left-arrow::right-arrow控制。

The grip can be styled be using the image property. The arrow indicators can by styled using the ::left-arrow subcontrol and the ::right-arrow subcontrol.

QComboBox

下拉框,外框样式可以使用盒子模型,下拉按钮可以使用::drop-down控制。默认的下拉按钮位于右上角。在下拉按钮上的箭头可以使用::down-arrow控制。默认的箭头处于矩形的中间位置。

The frame around the combobox can be styled using the box model. The drop-down button can be styled using the ::drop-down subcontrol. By default, the drop-down button is placed in the top right corner of the padding rectangle of the widget. The arrow mark inside the drop-down button can be styled using the ::down-arrow subcontrol. By default, the arrow is placed in the center of the contents rectangle of the drop-down subcontrol.

See Customizing QComboBox for an example.

QDateEdit

QSpinBox

See QSpinBox.

QDateTimeEdit

QSpinBox

See QSpinBox.

QDialog

对话框,仅支持background,background-clipbackground-origin属性。

Supports only the backgroundbackground-clip and background-origin properties.

Warning: Make sure you define the Q_OBJECT macro for your custom widget.

QDialogButtonBox

 

The layout of buttons can be altered using the button-layout property.

QDockWidget

悬停控件,支持工具条和按钮的悬停。它的边框可以使用border属性,::title控制外观,关闭按钮使用::close-button::float-button控制。

Supports styling of the title bar and the title bar buttons when docked.

The dock widget border can be styled using the border property. The ::title subcontrol can be used to customize the title bar. The close and float buttons are positioned with respect to the::title subcontrol using the ::close-button and ::float-button respectively.

When the title bar is vertical, the :vertical pseudo class is set. In addition, depending on QDockWidget::DockWidgetFeature, the :closable:floatable and :movable pseudo states are set.

Note: Use QMainWindow::separator to style the resize handle.

Warning: The style sheet has no effect when the QDockWidget is undocked as Qt uses native top level windows when undocked.

See Customizing QDockWidget for an example.

QDoubleSpinBox

 

See QSpinBox.

QFrame

框架类,支持盒子模型。4.3及以后版本如果使用QLabel则自动会被设置为QFrame::StyledPanel

Supports the box model.

Since 4.3, setting a stylesheet on a QLabel automatically sets the QFrame::frameStyle property to QFrame::StyledPanel.

See Customizing QFrame for an example.

QGroupBox

分组框,支持盒子模型。标题可以被::title定制,默认文本位置按照QGroupBox::textAlignment设置,如果分组框可以被check,则可以设置::indicatorspacing属性。

Supports the box model. The title can be styled using the ::title subcontrol. By default, the title is placed depending on QGroupBox::textAlignment.

In the case of a checkable QGroupBox, the title includes the check indicator. The indicator is styled using the the ::indicator subcontrol. The spacing property can be used to control the spacing between the text and indicator.

See Customizing QGroupBox for an example.

QHeaderView

支持盒子模型,被选择的头可以被::section控制,它支持:middle,:first,:last,:only-one,:only-one,:next-selected,

:previous-selected,:selected,:checked::up-arrow,

::down-arrow.

Supports the box model. The sections of the header view are styled using the ::section sub control. The section Sub-control supports the :middle:first:last:only-one:next-selected,:previous-selected:selected, and :checked pseudo states.

Sort indicator in can be styled using the ::up-arrow and the ::down-arrow Sub-control.

See Customizing QHeaderView for an example.

QLabel

标签,支持盒子模型。不支持:hover属性。

Supports the box model. Does not support the :hover pseudo-state.

Since 4.3, setting a stylesheet on a QLabel automatically sets the QFrame::frameStyle property to QFrame::StyledPanel.

See Customizing QFrame for an example (a QLabel derives from QFrame).

QLineEdit

行编辑框,支持盒子模型。选中文本颜色和背景颜色可以使用selection-colorselection-background-color设置。密码字符可以使用lineedit-password-character属性。

Support the box model.

The color and background of the selected item is styled using selection-color and selection-background-color respectively.

The password character can be styled using the lineedit-password-character property.

See Customizing QLineEdit for an example.

QListView

列表视图,支持盒子模型。当支持交替颜色时,交替颜色可以被alternate-background-color设置。选中项目的文本颜色和背景颜色可以使用selection-colorselection-background-color设置。选择行为可以使用show-decoration-selection设置。使用::item可以进行更多的设置。

Supports the box model. When alternating row colors is enabled, the alternating colors can be styled using the alternate-background-color property.

The color and background of the selected item is styled using selection-color and selection-background-color respectively.

The selection behavior is controlled by the show-decoration-selected property.

Use the ::item subcontrol for more fine grained control over the items in the QListView.

See QAbsractScrollArea to style scrollable backgrounds.

See Customzing QListView for an example.

QListWidget

 

See QListView.

QMainWindow

主窗口,支持分割(separator)属性,当使用QDockWidget时使用::separator控制。

Supports styling of the separator

The separator in a QMainWindow when using QDockWidget is styled using the ::separator subcontrol.

See Customizing QMainWindow for an example.

QMenu

菜单,支持盒子模型。可以使用::item单独控制每一项,它支持:selected,:default,:exclusive,:non-exclusive状态。指示器使用::indicator控制。分隔符使用::separator控制。子菜单的箭头可以使用left-arrowright-arrow控制。滚动条使用::sroller控制,关闭动作使用::tearoff控制。

Supports the box model.

Individual items are styled using the ::item subcontrol. In addition to the usually supported pseudo states, item subcontrol supports the :selected:default:exclusive and the non-exclusive pseudo states.

The indicator of checkable menu items is styled using the ::indicator subcontrol.

The separator is styled using the ::separator subcontrol.

For items with a sub menu, the arrow marks are styled using the right-arrow and left-arrow.

The scroller is styled using the ::scroller.

The tear-off is styled using the ::tearoff.

See Customizing QMenu for an example.

QMenuBar

Mac等系统中,菜单被更新到系统菜单区域,此时效果无效。

Supports the box model. The spacing property specifies the spacing between menu items. Individual items are styled using the ::item subcontrol.

Warning: When running on Qt/Mac, the menu bar is usually embedded into the system-wide menu bar. In this case, the style sheet will have no effect.

See Customizing QMenuBar for an example.

QMessageBox

信息框,使用messagebox-text-interaction-flags用于更新内部文本。

The messagebox-text-interaction-flags property can be used to alter the interaction with text in the message box.

QProgressBar

进度条,支持盒子模型。组块的样式使用::chunk控制。如果显示文本,使用text-align控制文本位置。不确定进度条使用:indeterminate 设置。

Supports the box model. The chunks of the progress bar can be styled using the ::chunk subcontrol. The chunk is displayed on the Contents rectangle of the widget.

If the progress bar displays text, use the text-align property to position the text.

Indeterminate progress bars have the :indeterminate pseudo state set.

See Customizing QProgressBar for an example.

QPushButton

按钮,支持盒子模型。支持:default,:flat, :checked状态。如果含有菜单,则菜单使用:menu-indicator控制。checked按钮外观可以使用:open:close状态。

警告:如果给QPushButton设置背景颜色(background-color)背景不一定会有效,除非你设置了border属性。这是因为默认的按钮绘制自身的border时会完全覆盖背景颜色。

QPushButton { background-color: red; border: none; }

Supports the box model. Supports the :default:flat:checked pseudo states.

For QPushButton with a menu, the menu indicator is styled using the ::menu-indicator subcontrol. Appearance of checkable push buttons can be customized using the :open and:closed pseudo-states.

Warning: If you only set a background-color on a QPushButton, the background may not appear unless you set the border property to some value. This is because, by default, theQPushButton draws a native border which completely overlaps the background-color. For example

QRadioButton

单选框,支持盒子模型。指示器使用::indicator控制。默认指示器位于左上角。spacing设置文本和指示器的间距。

Supports the box model. The check indicator can be styled using the ::indicator subcontrol. By default, the indicator is placed in the Top Left corner of the Contents rectangle of the widget.

The spacing property specifies the spacing between the check indicator and the text.

See Customizing QRadioButton for an example.

QScrollBar

滚动条,支持盒子模型。通过widthheight设置大小,通过:horizontal:vertical伪状态设置样式。滑块可以使用::handle设置,通过min-widthmin-height设置大小。::add-line控制下一行箭头,::sub-line控制上一行按钮,::sub-page::add-page分别定制上一页和下一页按钮行为。

Supports the box model. The Contents rectangle of the widget is considered to be the groove over which the slider moves. The extent of the QScrollBar (i.e the width or the height depending on the orientation) is set using the width or height property respectively. To determine the orientation, use the :horizontal and the :vertical pseudo states.

The slider can be styled using the ::handle subcontrol. Setting the min-width or min-height provides size contraints for the slider depending on the orientation.

The ::add-line subcontrol can be used to style the button to add a line. By default, the add-line subcontrol is placed in top right corner of the Border rectangle of the widget. Depending on the orientation the ::right-arrow or ::down-arrow. By default, the arrows are placed in the center of the Contents rectangle of the add-line subcontrol.

The ::sub-line subcontrol can be used to style the button to subtract a line. By default, the sub-line subcontrol is placed in bottom right corner of the Border rectangle of the widget. Depending on the orientation the ::left-arrow or ::up-arrow. By default, the arrows are placed in the center of the Contents rectangle of the sub-line subcontrol.

The ::sub-page subcontrol can be used to style the region of the slider that subtracts a page. The ::add-page subcontrol can be used to style the region of the slider that adds a page.

See Customizing QScrollBar for an example.

href="qthelp://com.trolltech.qtwidgets/qdoc/qsizegrip.html" QSizeGrip

 

Supports the widthheight, and image properties.

See Customizing QSizeGrip for an example.

QSlider

滑块条,支持盒子模型。min-width,height,min-height,width.

::groove设置滑块的样式。::handle定制翻页的行为。

Supports the box model. For horizontal slides, the min-width and height properties must be provided. For vertical sliders, the min-height and width properties must be provided.

The groove of the slider is styled using the ::groove. The groove is positioned by default in the Contents rectangle of the widget. The thumb of the slider is styled using ::handlesubcontrol. The subcontrol moves in the Contents rectangle of the groove subcontrol.

See Customizing QSlider for an example.

QSpinBox

支持黑子模型,使用::up-button::dow-button::up-arrow, ::down-arrow设置外观和行为。

The frame of the spin box can be styled using the box model.

The up button and arrow can be styled using the ::up-button and ::up-arrow subcontrols. By default, the up-button is placed in the top right corner in the Padding rectangle of the widget. Without an explicit size, it occupies half the height of its reference rectangle. The up-arrow is placed in the center of the Contents rectangle of the up-button.

The down button and arrow can be styled using the ::down-button and ::down-arrow subcontrols. By default, the down-button is placed in the bottom right corner in the Padding rectangle of the widget. Without an explicit size, it occupies half the height of its reference rectangle. The bottom-arrow is placed in the center of the Contents rectangle of the bottom-button.

See Customizing QSpinBox for an example.

QSplitter

 

Supports the box model. The handle of the splitter is styled using the ::handle subcontrol.

See Customizing QSplitter for an example.

QStatusBar

状态条,只支持background属性。使用::item控制单个条目。

Supports only the background property. The frame for individual items can be style using the ::item subcontrol.

See Customizing QStatusBar for an example.

QTabBar

Tab控件,单个Tab使用::tab控制,关闭按钮使用::close-button

它支持:only-one, :first, :last, :middle, :previous--selected, 

:next-selected,:selected伪状态。:top, :left, :right, :bottom

伪状态依赖框架位置。tear indicator使用::tear控制。

滚动条使用QTabBar QToolButton筛选器,可以通过::scroller控制

alignment设置对其方式。

Individual tabs may be styled using the ::tab subcontrol. Close buttons using the ::close-button The tabs support the :only-one:first:last:middle:previous--selected:next-selected,:selected pseudo states.

The :top:left:right:bottom pseudo states depending on the orientation of the tabs.

Overlapping tabs for the selected state are created by using negative margins or using the absolute position scheme.

The tear indicator of the QTabBar is styled using the ::tear subcontrol.

QTabBar used two QToolButtons for its scrollers that can be styled using the QTabBar QToolButton selector. To specify the width of the scroll button use the ::scroller subcontrol.

The alignment of the tabs within the QTabBar is styled using the alignment property.

Warning:

To change the position of the QTabBar within a QTabWidget, use the tab-bar subcontrol (and set subcontrol-position).

See Customizing QTabBar for an example.

QTabWidget

 

The frame of the tab widget is styled using the ::pane subcontrol. The left and right corners are styled using the ::left-corner and ::right-corner respectively. The position of the tab bar is controlled using the ::tab-bar subcontrol.

By default, the subcontrols have positions of a QTabWidget in the QWindowsStyle. To place the QTabBar in the center, set the subcontrol-position of the tab-bar subcontrol.

The :top:left:right:bottom pseudo states depending on the orientation of the tabs.

See Customizing QTabWidget for an example.

QTableView

 

Supports the box model. When alternating row colors is enabled, the alternating colors can be styled using the alternate-background-color property.

The color and background of the selected item is styled using selection-color and selection-background-color respectively.

The corner widget in a QTableView is implemented as a QAbstractButton and can be styled using the "QTableView QTableCornerButton::section" selector.

Warning: If you only set a background-color on a QTableCornerButton, the background may not appear unless you set the border property to some value. This is because, by default, the QTableCornerButton draws a native border which completely overlaps the background-color.

The color of the grid can be specified using the gridline-color property.

See QAbsractScrollArea to style scrollable backgrounds.

See Customzing QTableView for an example.

QTableWidget

 

See QTableView.

QTextEdit

文本框,支持盒子模型,选择的文本颜色和背景颜色使用selection-colorselection-background-color

Supports the box model.

The color and background of selected text is styled using selection-color and selection-background-color respectively.

See QAbsractScrollArea to style scrollable backgrounds.

QTimeEdit

 

See QSpinBox.

QToolBar

工具条,支持盒子模型。:top, :left, :right, :bottom

:first, :last, :middle, :only-one。分隔符使用::separator定义风格

行为使用::handle控制。

Supports the box model.

The :top:left:right:bottom pseudo states depending on the area in which the tool bar is grouped.

The :first:last:middle:only-one pseudo states indicator the position of the tool bar within a line group (See QStyleOptionToolBar::positionWithinLine).

The separator of a QToolBar is styled using the ::separator subcontrol.

The handle (to move the toolbar) is styled using the ::handle subcontrol.

See Customizing QToolBar for an example.

QToolButton

 

Supports the box model.

If the QToolButton has a menu, is ::menu-indicator subcontrol can be used to style the indicator. By default, the menu-indicator is positioned at the bottom right of the Padding rectangle of the widget.

If the QToolButton is in QToolButton::MenuButtonPopup mode, the ::menu-button subcontrol is used to draw the menu button. ::menu-arrow subcontrol is used to draw the menu arrow inside the menu-button. By default, it is positioned in the center of the Contents rectangle of the menu-button subcontrol.

When the QToolButton displays arrows, the ::up-arrow::down-arrow::left-arrow and ::right-arrow subcontrols are used.

Warning: If you only set a background-color on a QToolButton, the background will not appear unless you set the border property to some value. This is because, by default, theQToolButton draws a native border which completely overlaps the background-color. For example,

 QToolButton { background-color: red; border: none; }

See Customizing QToolButton for an example.

QToolBox

 

Supports the box model.

The individual tabs can by styled using the ::tab subcontrol. The tabs support the :only-one:first:last:middle:previous-selected:next-selected:selected pseudo states.

QToolTip

 

Supports the box model. The opacity property controls the opacity of the tooltip.

See Customizing QFrame for an example (a QToolTip is a QFrame).

QTreeView

 

Supports the box model. When alternating row colors is enabled, the alternating colors can be styled using the alternate-background-color property.

The color and background of the selected item is styled using selection-color and selection-background-color respectively.

The selection behavior is controlled by the show-decoration-selected property.

The branches of the tree view can be styled using the ::branch subcontrol. The ::branch Sub-control supports the :open:closed:has-sibling and :has-children pseudo states.

Use the ::item subcontrol for more fine grained control over the items in the QTreeView.

See QAbsractScrollArea to style scrollable backgrounds.

See Customizing QTreeView for an example to style the branches.

QTreeWidget

 

See QTreeView.

QWidget

 

Supports only the backgroundbackground-clip and background-origin properties.

If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below:

 void CustomWidget::paintEvent(QPaintEvent *)

 {

     QStyleOption opt;

     opt.init(this);

     QPainter p(this);

     style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);

 }

The above code is a no-operation if there is no stylesheet set.

Warning: Make sure you define the Q_OBJECT macro for your custom widget.


0 0
原创粉丝点击