qt QTableView/QTableWidget样式设置

Posted 大陈1108

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了qt QTableView/QTableWidget样式设置相关的知识,希望对你有一定的参考价值。

转载请注明出处: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); 

  

以上是关于qt QTableView/QTableWidget样式设置的主要内容,如果未能解决你的问题,请参考以下文章

Linux 打包 QT 程序

QT学习之QT 下载安装

Qt 找不到服务 - “org.qt-project.qt.mediaplayer”

[QT]加快qt编译:设置默认多核编译qt

qt + opengl 开发环境的搭建

qt creator和qt的区别