Customizing QTabWidget and QTabBar

cpp 复制代码
 QTabWidget::pane { /* The tab widget frame */
     border-top: 2px solid #C2C7CB;
 }

 QTabWidget::tab-bar {
     left: 5px; /* move to the right by 5px */
 }

 QTabBar::tab {
     background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                 stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
                                 stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
     border: 2px solid #C4C4C3;
     border-bottom-color: #C2C7CB; /* same as the pane color */
     border-top-left-radius: 4px;
     border-top-right-radius: 4px;
     min-width: 8ex;
     padding: 2px;
 }

1、QTabWidget::pane 是按钮与主窗体之间的线条

QTabWidget::pane { border-top: 8px solid red;} 的效果:

2、QTabWidget::tab-bar 按钮

QTabWidget::tab-bar {left: 300px;}

QTabWidget::tab-bar {alignment: center; }

3、烤串效果

cpp 复制代码
QTabWidget::pane {

border-top: 2px solid #C2C7CB;

position: absolute;

top: -0.5em;

}



QTabWidget::tab-bar {

alignment: center;

}

4、tab 按钮

QTabBar::tab {background: red;}

5、tab 按钮突出效果

cpp 复制代码
 QTabBar::tab {
     background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                 stop: 0 #D0D1FD,  stop: 1.0 #FFFFFF);
   
     border: 2px solid red;
     border-bottom-color: #C2C7CB; /* same as the pane color */
     border-top-left-radius: 5px;
     border-top-right-radius: 5px;
     min-width: 100%;
     max-width: 150%;
     padding: 2px;
 }
 QTabBar::tab:!selected {
     margin-top: 20px; /* make non-selected tabs look smaller */
 }

6、tab 按钮点击、悬停、选中效果

cpp 复制代码
 QTabWidget::pane { /* The tab widget frame */
     border-top: 2px solid #C2C7CB;
 }

 QTabWidget::tab-bar {
     left: 5px; /* move to the right by 5px */
 }

 /* Style the tab using the tab sub-control. Note that
     it reads QTabBar _not_ QTabWidget */
 QTabBar::tab {
     background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                 stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
                                 stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
     border: 2px solid #C4C4C3;
     border-bottom-color: #C2C7CB; /* same as the pane color */
     border-top-left-radius: 4px;
     border-top-right-radius: 4px;
     min-width: 8ex;
     padding: 2px;
 }

 QTabBar::tab:selected, QTabBar::tab:hover {
     background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                 stop: 0 #fafafa, stop: 0.4 #f4f4f4,
                                 stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
 }

 QTabBar::tab:selected {
     border-color: #9B9B9B;
     border-bottom-color: #C2C7CB; /* same as pane color */
 }

 QTabBar::tab:!selected {
     margin-top: 2px; /* make non-selected tabs look smaller */
 }

 /* make use of negative margins for overlapping tabs */
 QTabBar::tab:selected {
     /* expand/overlap to the left and right by 4px */
     margin-left: -4px;
     margin-right: -4px;
 }

 QTabBar::tab:first:selected {
     margin-left: 0; /* the first selected tab has nothing to overlap with on the left */
 }

 QTabBar::tab:last:selected {
     margin-right: 0; /* the last selected tab has nothing to overlap with on the right */
 }

 QTabBar::tab:only-one {
     margin: 0; /* if there is only one tab, we don't want overlapping margins */
 }
相关推荐
SunkingYang12 天前
QT中QWidget和QObject的区别与联系是什么
qt·qobject·qwidget·区别·联系
StruggleRookie21 天前
ubuntu20.4安装Qt5.15.2
ubuntu·qt5
HelloTonyGo23 天前
QT5实现https的post请求(QNetworkAccessManager、QNetworkRequest和QNetworkReply)
https·wireshark·ssl·post·qt5
29747860481 个月前
Qt基础类03-直线类QLine
qt·qt5·qline·qlinef·直线类
29747860481 个月前
QT基础之【模块】
模块·module·入门·基础·qt5
yayapoi~1 个月前
qml formLayout实现方式
qt5·qml
Whale_XH2 个月前
基于QT实现的简易WPS(已开源)
wps·qt5·qt项目
炫酷的伊莉娜2 个月前
【QT】常用控件(概述、QWidget核心属性、按钮类控件、显示类控件、输入类控件、多元素控件、容器类控件、布局管理器)
qt·qt creator·控件·qt5·qwidget
南猿北者2 个月前
Qt窗口介绍
笔记·qt·学习·qt5
炫酷的伊莉娜2 个月前
【QT】QT 概述(背景介绍、搭建开发环境、Qt Creator、程序、项目文件解析、编程注意事项)
c++·qt·ui·qt creator·qt5·对象树