Qt筆記-TabWidget

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(“}”);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章