Qt笔记-TabWidget

来源:互联网 发布:网络黄金egd还有希望吗 编辑:程序博客网 时间:2024/06/07 13:17

QTabWidget的QSS笔记:
方法一: 要做到Tab与下面的图连在一起,不要设置QTabBar::tab的border,而是使用图片,同时QTabWidget::pane需要设置一下跟QTabBar::tab:selected相近处的色彩接近,这样就好像完全连在一起了
例子:
QTabWidget::pane { /* The tab widget frame */
border:0px solid;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px;
background-color: #2EA0DC;
}
QTabWidget::tab-bar {
left: 0px; /* move to the right by 5px */
}
/* Style the tab using the tab sub-control. Note that
it reads QTabBar not QTabWidget */
QTabBar::tab {
min-width: 104px;
min-height: 29px;
padding:1px; /* 留出空白 */
color: rgb(255, 255, 255);
}
/* 没有使用border ,selected图片大一点*/
QTabBar::tab:selected {
background: url(:/image/400SampleApply/Tab/TabBarButton1.png) no-repeat;
}
/* 没有使用border , !selected图片小一点*/
QTabBar::tab:!selected {
background: url(:/image/400SampleApply/Tab/TabBarButton2.png) no-repeat;
}

方法二:不使用图片,纯QSS
strStyle.append(“QTabWidget::pane { “); /* The tab widget frame */
strStyle.append(” border:0px solid;”);
strStyle.append(” border-top-right-radius: 4px;”);
strStyle.append(” border-bottom-right-radius: 4px;”);
strStyle.append(” border-bottom-left-radius: 4px;”);
//采用与 EStyle_Frame_Outside 一样的背景设置,是为了一致性
strStyle.append(” background-color: white; “);
strStyle.append(” }”);
strStyle.append(“QTabWidget::tab-bar {“);
strStyle.append(” left: 0px; “);
strStyle.append(“}”);
/* Style the tab using the tab sub-control. Note that it reads QTabBar not QTabWidget */
strStyle.append(“QTabBar::tab {“);
strStyle.append(” min-width: 104px;”);
strStyle.append(” min-height: 29px;”);
strStyle.append(” color: rgb(255, 255, 255);”);
strStyle.append(“}”);
strStyle.append(“QTabBar::tab:selected {“);
//strStyle.append(“background: url(:/image/400Style/TabWidget/TabBarSelected.png) no-repeat;”);
strStyle.append(” background: white; “);
strStyle.append( this->TextColorH1() );
strStyle.append(” border-top-right-radius: 4px;”);
strStyle.append(” border-top-left-radius: 4px;”);
strStyle.append(” margin-right: 2px;”);
strStyle.append(” padding-bottom:2px; “);//跟 !selected的margin-bottom: 2px;对应,文字不会动
strStyle.append(“}”);
strStyle.append(“QTabBar::tab:!selected {“);
strStyle.append(” background: #DEDEDE; “);
strStyle.append( this->TextColorH1() );
strStyle.append(” border-top-right-radius: 4px;”);
strStyle.append(” border-top-left-radius: 4px;”);
strStyle.append(” margin-right: 2px;”);
strStyle.append(” margin-bottom: 2px;”);
strStyle.append(“}”);

原创粉丝点击