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 */
 }
相关推荐
艾莉丝努力练剑1 天前
【QT】信号与槽
linux·开发语言·c++·人工智能·windows·qt·qt5
小小码农Come on9 天前
QPushButton QSS(一):按钮常用qss
前端·javascript·css·qt5
习惯就好zz11 天前
[实战笔记] 从 Qt 5.12.9 跨越到 Qt 6.x 完美迁移指南 (Windows + VS)
windows·qt·msvc·qt5·qt6·迁移
艾莉丝努力练剑13 天前
【QT】Qt 从零上手:Hello World、项目文件与实战避坑指南
linux·运维·开发语言·c++·qt·继承·qt5
hqwest18 天前
码上通QT实战25--报警页面01-报警布局设计
开发语言·qt·qwidget·ui设计·qt布局控件
艾莉丝努力练剑19 天前
【QT】环境搭建收尾:认识Qt Creator
运维·开发语言·c++·人工智能·qt·qt creator·qt5
hqwest23 天前
码上通QT实战10--监控页面02-绘制温度盘
开发语言·qt·自定义控件·qwidget·提升部件·qt绘图
飞仔FeiZai1 个月前
基于 Python 与 PyQt5 构建的特斯拉行车记录仪视频播放器
python·音视频·qt5
hqwest1 个月前
码上通QT实战01--创建项目
开发语言·qt·sqlite3·qt项目·qwidget·qwindow
微尘hjx1 个月前
【目标检测软件 02】AirsPy 目标检测系统操作指南
人工智能·测试工具·yolo·目标检测·计算机视觉·目标跟踪·qt5