Qt常用样式表

13 篇文章 0 订阅

一、基本语法Syntax

控件类名#控件名{qss语句} 蓝色部分可不写

Example:

QPushButton#okBtn{color:red}

多个控件则以逗号隔开:

QPushButton, QLineEdit, QComboBox { color: red }

QLabel { border-width: 1px 2px 3px 4px } /* 上1px 右2px 下3px 左4px */

二、属性Properties

(具体可查看Qt助手)

属性

类型

描述

alternate-background-color

Brush

交替背景颜色

QTreeView {

alternate-background-color: blue;

background: yellow;

}

background

Background

背景

background-color

Brush

背景颜色

QFrame{background-image: url(:/images/hydro.png) }

background-image

Url

背景图片

background-repeat

Repeat

背景重复方向(x,y)

background-position

Alignment

背景图片位置

background-attachment

Attachment

背景图片固定/滚动

background-clip

Origin

背景画的位置

QFrame {

background-image: url(:/images/header.png);

background-position: top left;

background-origin: content;

background-clip: padding;

}

background-origin

Origin

背景画的位置

border

Border

边框

QLineEdit { border: 1px solid white }

border-top

Border

上边框

border-right

Border

右边框

border-bottom

Border

下边框

border-left

Border

左边框

border-color

Box Colors

边框颜色

border-top-color

Brush

上边框颜色

border-right-color

Brush

右边框颜色

border-bottom-color

Brush

下边框颜色

border-left-color

Brush

左边框颜色

border-image

Border Image

边框图片

border-radius

Radius

边框弧度

border-top-left-radius

Radius

边框左上角弧度

border-top-right-radius

Radius

边框右上角弧度

border-bottom-right-radius

Radius

边框右下角弧度

border-bottom-left-radius

Radius

边框左上角弧度

border-style

Border Style

边框样式

QLineEdit {

border-width: 2px;

border-style: solid;

border-color: darkblue;

}

border-top-style

Border Style

上边框样式

border-right-style

Border Style

右边框样式

border-bottom-style

Border Style

下边框样式

border-left-style

Border Style

左边框样式

border-width

Box Lengths

边框宽度

border-top-width

Length

上边框宽度

border-right-width

Length

右边框宽度

border-bottom-width

Length

下边框宽度

border-left-width

Length

左边框宽度

bottom

Length

SubControl位置

button-layout

Number

弹框/消息框按钮布局

color

Brush

文字颜色

dialogbuttonbox-buttons-have-icons

Boolean

弹窗是否显示图标

font

Font

字体

QCheckBox { font: bold italic large "Times New Roman" }

font-family

String

字体组

QCheckBox { font-family: "New Century Schoolbook" }

font-size

Font Size

字体大小

font-style

Font Style

字体风格

font-weight

Font Weight

字重

gridline-color*

Color

QTableView网格线颜色

height

Length

高度

icon-size

Length

图标尺寸

image*

Url+

SubControl 图片

QSpinBox::down-button { image: url(:/images/spindown.png) }

image-position

alignment

图片位置

left

Length

SubControl位置

QSpinBox::down-button { left: 2px }

lineedit-password-character*

Number

lineedit-password-mask-delay*

Number

margin

Box Lengths

外边距

margin-top

Length

上边距

margin-right

Length

右边距

margin-bottom

Length

下边距

margin-left

Length

左边距

max-height

Length

最大高度

max-width

Length

最大宽度

messagebox-text-interaction-flags*

Number

消息窗口文本交互行为

QMessageBox { messagebox-text-interaction-flags: 5 }

min-height

Length

最小高度

min-width

Length

最小宽度

opacity*

Number

透明度(0-255)

padding

Box Lengths

内边距

padding-top

Length

上边距

padding-right

Length

右边距

padding-bottom

Length

下边距

padding-left

Length

左边距

paint-alternating-row-colors-for-empty-area

bool

QTreeView空白处是否填充颜色

position

relative | absolute

Offsets

right

Length

SubControl位置

QSpinBox::down-button { right: 2px }

selection-background-color*

Brush

选中的text/items背景颜色

selection-color*

Brush

选中的text/items背景颜色

QTextEdit { selection-color: white }

show-decoration-selected*

Boolean

QListView选中时效果 整行或文字的长度

spacing*

Length

内间距

QMenuBar { spacing: 10 }

subcontrol-origin*

Origin

位置

subcontrol-position*

Alignment

位置

QSpinBox::down-button {

image: url(:/images/spindown.png);

subcontrol-origin: padding;

subcontrol-position: right bottom;

}

text-align

Alignment

文本对齐方式

QPushButton {

text-align: left;

}

text-decoration

none

underline

overline

line-through

文本装饰

top

Length

SubControl位置

width

Length

SubControl位置

QSpinBox::up-button { width: 12px }

三、状态Pesudo-States

Qt 5.4.2

Pseudo-State

Description

:active

This state is set when the widget resides in an active window.

:adjoins-item

This state is set when the ::branch of a QTreeView is adjacent to an item.

:alternate

This state is set for every alternate row whe painting the row of a QAbstractItemView when QAbstractItemView::alternatingRowColors() is set to true.

:bottom

The item is positioned at the bottom. For example, a QTabBar that has its tabs positioned at the bottom.

:checked

The item is checked. For example, the checked state of QAbstractButton.

:closable

The items can be closed. For example, the QDockWidget has the QDockWidget::DockWidgetClosable feature turned on.

:closed

The item is in the closed state. For example, an non-expanded item in a QTreeView

:default

The item is the default. For example, a default QPushButton or a default action in a QMenu.

:disabled

The item is disabled.

:editable

The QComboBox is editable.

:edit-focus

The item has edit focus (See QStyle::State_HasEditFocus). This state is available only for Qt Extended applications.

:enabled

The item is enabled.

:exclusive

The item is part of an exclusive item group. For example, a menu item in a exclusive QActionGroup.

:first

The item is the first (in a list). For example, the first tab in a QTabBar.

:flat

The item is flat. For example, a flat QPushButton.

:floatable

The items can be floated. For example, the QDockWidget has the QDockWidget::DockWidgetFloatable feature turned on.

:focus

The item has input focus.

:has-children

The item has children. For example, an item in a QTreeView that has child items.

:has-siblings

The item has siblings. For example, an item in a QTreeView that siblings.

:horizontal

The item has horizontal orientation

:hover

The mouse is hovering over the item.

:indeterminate

The item has indeterminate state. For example, a QCheckBox or QRadioButton is partially checked.

:last

The item is the last (in a list). For example, the last tab in a QTabBar.

:left

The item is positioned at the left. For example, a QTabBar that has its tabs positioned at the left.

:maximized

The item is maximized. For example, a maximized QMdiSubWindow.

:middle

The item is in the middle (in a list). For example, a tab that is not in the beginning or the end in a QTabBar.

:minimized

The item is minimized. For example, a minimized QMdiSubWindow.

:movable

The item can be moved around. For example, the QDockWidget has the QDockWidget::DockWidgetMovable feature turned on.

:no-frame

The item has no frame. For example, a frameless QSpinBox or QLineEdit.

:non-exclusive

The item is part of a non-exclusive item group. For example, a menu item in a non-exclusive QActionGroup.

:off

For items that can be toggled, this applies to items in the "off" state.

:on

For items that can be toggled, this applies to widgets in the "on" state.

:only-one

The item is the only one (in a list). For example, a lone tab in a QTabBar.

:open

The item is in the open state. For example, an expanded item in a QTreeView, or a QComboBox or QPushButton with an open menu.

:next-selected

The next item (in a list) is selected. For example, the selected tab of a QTabBar is next to this item.

:pressed

The item is being pressed using the mouse.

:previous-selected

The previous item (in a list) is selected. For example, a tab in a QTabBar that is next to the selected tab.

:read-only

The item is marked read only or non-editable. For example, a read only QLineEdit or a non-editable QComboBox.

:right

The item is positioned at the right. For example, a QTabBar that has its tabs positioned at the right.

:selected

The item is selected. For example, the selected tab in a QTabBar or the selected item in a QMenu.

:top

The item is positioned at the top. For example, a QTabBar that has its tabs positioned at the top.

:unchecked

The item is unchecked.

:vertical

The item has vertical orientation.

:window

The widget is a window (i.e top level widget)

四、子控件Sub-Controls

Qt 5.4.2

Sub-Control

Description

::add-line

The button to add a line of a QScrollBar.

::add-page

The region between the handle (slider) and the add-line of a QScrollBar.

::branch

The branch indicator of a QTreeView.

::chunk

The progress chunk of a QProgressBar.

::close-button

The close button of a QDockWidget or tabs of QTabBar

::corner

The corner between two scrollbars in a QAbstractScrollArea

::down-arrow

The down arrow of a QComboBox, QHeaderView (sort indicator), QScrollBar or QSpinBox.

::down-button

The down button of a QScrollBar or a QSpinBox.

::drop-down

The drop-down button of a QComboBox.

::float-button

The float button of a QDockWidget

::groove

The groove of a QSlider.

::indicator

The indicator of a QAbstractItemView, a QCheckBox, a QRadioButton, a checkable QMenu item or a checkable QGroupBox.

::handle

The handle (slider) of a QScrollBar, a QSplitter, or a QSlider.

::icon

The icon of a QAbstractItemView or a QMenu.

::item

An item of a QAbstractItemView, a QMenuBar, a QMenu, or a QStatusBar.

::left-arrow

The left arrow of a QScrollBar.

::left-corner

The left corner of a QTabWidget. For example, this control can be used to control position the left corner widget in a QTabWidget.

::menu-arrow

The arrow of a QToolButton with a menu.

::menu-button

The menu button of a QToolButton.

::menu-indicator

The menu indicator of a QPushButton.

::right-arrow

The right arrow of a QMenu or a QScrollBar.

::pane

The pane (frame) of a QTabWidget.

::right-corner

The right corner of a QTabWidget. For example, this control can be used to control the position the right corner widget in a QTabWidget.

::scroller

The scroller of a QMenu or QTabBar.

::section

The section of a QHeaderView.

::separator

The separator of a QMenu or in a QMainWindow.

::sub-line

The button to subtract a line of a QScrollBar.

::sub-page

The region between the handle (slider) and the sub-line of a QScrollBar.

::tab

The tab of a QTabBar or QToolBox.

::tab-bar

The tab bar of a QTabWidget. This subcontrol exists only to control the position of the QTabBar inside the QTabWidget. To style the tabs using the ::tab subcontrol.

::tear

The tear indicator of a QTabBar.

::tearoff

The tear-off indicator of a QMenu.

::text

The text of a QAbstractItemView.

::title

The title of a QGroupBox or a QDockWidget.

::up-arrow

The up arrow of a QHeaderView (sort indicator), QScrollBar or a QSpinBox.

::up-button

The up button of a QSpinBox.

五、QTreeWidget-树形列表样式

QTreeWidget样式

六、QTableWidget-表格样式

QTableWidget样式

七、QScrollBar-滚动条样式

QScrollBar样式

八、QComboBox-下拉框样式

QComboBox样式

九、QCheckBox-复选框样式

QCheckBox样式

后续更新……

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值