tablewidget样式_qt QTableView/QTableWidget样式设置

本文介绍了如何自定义Qt中的QTableView和QTableWidget的样式,包括选中项背景、表头、滚动条和行间颜色渐变。通过CSS样式的设置,实现了个性化界面效果。
摘要由CSDN通过智能技术生成

转载请注明出处:http://www.cnblogs.com/dachen408/p/7591409.html

选中设置:

QTableView::item:selected

{

background:rgb(0,0,100);

color:white;

}

表头设置:

QHeaderView::section:first

{

border-image: url(:/images/expand/tempUser_headBg2.png);

height: 30px;

font: 11pt "微软雅黑";

}

QHeaderView::section:middle

{

border-image: url(:/images/expand/tempUser_headBg2.png);

height: 30px;

font: 11pt "微软雅黑";

}

QHeaderView::section:last

{

border-image: url(:/images/expand/tempUser_headBg4.png);

height: 30px;

font: 11pt "微软雅黑";

}

滚动条设置:

QScrollBar:vertical {

border: 0px;

background:rgba(255,255,255,0);

border-image:url(:/images/scrollbar/vertical_scrollBg.png);

width: 22px;

margin: 22px 0 22px 0;

}

QScrollBar::handle:vertical {

border-image:url(:/images/scrollbar/vertical_slide.png);

width:22px;

min-height:50px;

max-height:200px;

}

QScrollBar::handle:vertical:hover {

border-image: url(:/images/scrollbar/vertical_slide_hover.png);

width:22px;

min-height:50px;

max-height:200px;

}

QScrollBar::handle:horizontal:hover {

border-image: url(:/images/scrollbar/slide.png);

width:22px;

min-height:35px;

}

QScrollBar::handle:vertical:hover {

border-image:url(:/images/scrollbar/vertical_slide_hover.png);

width:22px;

}

QScrollBar::add-line:vertical {

border-image:url(:/images/scrollbar/vertical_down.png);

height: 22px;

subcontrol-position: bottom;

subcontrol-origin: margin;

}

QScrollBar::add-line:vertical:pressed{

border-image:url(:/images/scrollbar/vertical_down_down.png);

height: 22px;

subcontrol-position: bottom;

subcontrol-origin: margin;

}

QScrollBar::sub-line:vertical {

border-image:url(:/images/scrollbar/vertical_up.png);

height:22px;

subcontrol-position: top;

subcontrol-origin: margin;

}

QScrollBar::sub-line:vertical:pressed {

border-image:url(:/images/scrollbar/vertical_up_down.png);

height: 22px;

subcontrol-position: top;

subcontrol-origin: margin;

}

QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {

background: none;

}

QScrollBar:horizontal {

border: 0px;

background:rgba(255,255,255,0);

border-image:url(:/images/scrollbar/scrollBg.png);

height: 22px;

margin: 0 22px 0 22px;

}

QScrollBar::handle:horizontal {

border-image:url(:/images/scrollbar/slide.png);

height:22px;

}

QScrollBar::handle:vertical:hover {

border-image:url(:/images/scrollbar/vertical_slide_hover.png);

width:22px;

}

QScrollBar::add-line:horizontal {

border-image:url(:/images/scrollbar/down.png);

width: 22px;

subcontrol-position: right;

subcontrol-origin: margin;

}

QScrollBar::add-line:horizontal:pressed{

border-image:url(:/images/scrollbar/down_down.png);

width: 22px;

subcontrol-position: right;

subcontrol-origin: margin;

}

QScrollBar::sub-line:horizontal {

border-image:url(:/images/scrollbar/up.png);

width:22px;

subcontrol-position: left;

subcontrol-origin: margin;

}

QScrollBar::sub-line:horizontal:pressed {

border-image:url(:/images/scrollbar/up_down.png);

width: 22px;

subcontrol-position: left;

subcontrol-origin: margin;

}

QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {

background: none;

}

行之间颜色渐变(alternaingRowColors必须设置为true):

QTableView

{

background-color: rgb(255, 255, 255);

alternate-background-color:#F2F8FF;

}

设置QTreeWidget水平滚动条:

ui.treeWidget_site->header()->setSectionResizeMode(QHeaderView::ResizeToContents);

ui.treeWidget_site->header()->setStretchLastSection(false);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值