当前位置: 首页 > news >正文

Qt的QTabWidget样式设置

QTabWidget 是 Qt 框架中用于创建选项卡式界面的控件。可以通过样式表(QSS,Qt Style Sheets)来设置 QTabWidget 的外观。以下是一些常见的样式设置示例:

1. 基本样式设置

tab_widget.setStyleSheet("""
    QTabWidget::pane {
        border: 1px solid #ccc;
        background-color: #f0f0f0;
    }
    QTabBar::tab {
        background: #ddd;
        border: 1px solid #ccc;
        padding: 10px;
        font-size: 14px;
    }
    QTabBar::tab:selected {
        background: #f0f0f0;
        border-bottom-color: #f0f0f0;
    }
    QTabBar::tab:hover {
        background: #eee;
    }
""")

2. 设置选项卡的宽度和高度

tab_widget.setStyleSheet("""
    QTabBar::tab {
        width: 100px;
        height: 30px;
    }
""")

3. 设置选项卡的圆角

tab_widget.setStyleSheet("""
    QTabBar::tab {
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
    }
""")

4. 设置选项卡的背景颜色和字体颜色

tab_widget.setStyleSheet("""
    QTabBar::tab {
        background: #555;
        color: white;
    }
    QTabBar::tab:selected {
        background: #777;
        color: yellow;
    }
""")

5. 设置选项卡的图标和文本对齐方式

tab_widget.setStyleSheet("""
    QTabBar::tab {
        padding-left: 20px; /* 图标和文本之间的间距 */
        text-align: left; /* 文本左对齐 */
    }
""")

6. 设置选项卡的关闭按钮

tab_widget.setStyleSheet("""
    QTabBar::close-button {
        image: url(close.png); /* 关闭按钮的图标 */
        subcontrol-position: right; /* 关闭按钮的位置 */
    }
    QTabBar::close-button:hover {
        background: #f00; /* 鼠标悬停时的背景颜色 */
    }
""")

7. 设置选项卡的边框和间距

tab_widget.setStyleSheet("""
    QTabWidget::pane {
        border: 2px solid #ccc;
        margin: 0px;
        padding: 0px;
    }
    QTabBar::tab {
        margin: 0px;
        padding: 5px;
    }
""")

8. 设置选项卡的渐变背景

tab_widget.setStyleSheet("""
    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);
    }
    QTabBar::tab:selected {
        background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                    stop: 0 #fafafa, stop: 1 #f0f0f0);
    }
""")

9. 设置选项卡的阴影效果

tab_widget.setStyleSheet("""
    QTabBar::tab {
        border: 1px solid #ccc;
        border-bottom-color: #f0f0f0; /* 底部边框颜色 */
        margin-right: 2px; /* 选项卡之间的间距 */
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1); /* 阴影效果 */
    }
""")

10. 设置选项卡的字体

tab_widget.setStyleSheet("""
    QTabBar::tab {
        font-family: Arial;
        font-size: 12px;
        font-weight: bold;
    }
""")

11. 设置选项卡的图标

tab_widget.setStyleSheet("""
    QTabBar::tab {
        icon-size: 24px; /* 图标大小 */
    }
""")

12. 设置选项卡的悬停效果

tab_widget.setStyleSheet("""
    QTabBar::tab:hover {
        background: #eee;
        color: #000;
    }
""")

13. 设置选项卡的禁用状态

tab_widget.setStyleSheet("""
    QTabBar::tab:disabled {
        background: #ccc;
        color: #888;
    }
""")

14. 设置选项卡的选中状态

tab_widget.setStyleSheet("""
    QTabBar::tab:selected {
        background: #f0f0f0;
        border-bottom-color: #f0f0f0;
    }
""")

15. 设置选项卡的底部边框

tab_widget.setStyleSheet("""
    QTabBar::tab {
        border-bottom: 2px solid #ccc;
    }
    QTabBar::tab:selected {
        border-bottom: 2px solid #f00;
    }
""")

16. 设置选项卡的顶部边框

tab_widget.setStyleSheet("""
    QTabBar::tab {
        border-top: 2px solid #ccc;
    }
    QTabBar::tab:selected {
        border-top: 2px solid #f00;
    }
""")

17. 设置选项卡的左右边框

tab_widget.setStyleSheet("""
    QTabBar::tab {
        border-left: 2px solid #ccc;
        border-right: 2px solid #ccc;
    }
    QTabBar::tab:selected {
        border-left: 2px solid #f00;
        border-right: 2px solid #f00;
    }
""")

18. 设置选项卡的背景图片

tab_widget.setStyleSheet("""
    QTabBar::tab {
        background-image: url(tab_bg.png);
    }
    QTabBar::tab:selected {
        background-image: url(tab_bg_selected.png);
    }
""")

19. 设置选项卡的渐变边框

tab_widget.setStyleSheet("""
    QTabBar::tab {
        border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #ccc, stop: 1 #999);
    }
    QTabBar::tab:selected {
        border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #f00, stop: 1 #c00);
    }
""")

20. 设置选项卡的圆角边框

tab_widget.setStyleSheet("""
    QTabBar::tab {
        border: 1px solid #ccc;
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
    }
    QTabBar::tab:selected {
        border: 1px solid #f00;
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
    }
""")

21. 设置选项卡的阴影边框

tab_widget.setStyleSheet("""
    QTabBar::tab {
        border: 1px solid #ccc;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
    QTabBar::tab:selected {
        border: 1px solid #f00;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
""")

22. 设置选项卡的渐变背景和边框

tab_widget.setStyleSheet("""
    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: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #ccc, stop: 1 #999);
    }
    QTabBar::tab:selected {
        background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                    stop: 0 #fafafa, stop: 1 #f0f0f0);
        border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #f00, stop: 1 #c00);
    }
""")

23. 设置选项卡的渐变背景和圆角边框

tab_widget.setStyleSheet("""
    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: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #ccc, stop: 1 #999);
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
    }
    QTabBar::tab:selected {
        background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                    stop: 0 #fafafa, stop: 1 #f0f0f0);
        border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #f00, stop: 1 #c00);
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
    }
""")

24. 设置选项卡的渐变背景和阴影边框

tab_widget.setStyleSheet("""
    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: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #ccc, stop: 1 #999);
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
    QTabBar::tab:selected {
        background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                    stop: 0 #fafafa, stop: 1 #f0f0f0);
        border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #f00, stop: 1 #c00);
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
""")

25. 设置选项卡的渐变背景和圆角阴影边框

tab_widget.setStyleSheet("""
    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: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #ccc, stop: 1 #999);
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
    QTabBar::tab:selected {
        background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                    stop: 0 #fafafa, stop: 1 #f0f0f0);
        border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #f00, stop: 1 #c00);
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
""")

26. 设置选项卡的渐变背景和圆角阴影边框

tab_widget.setStyleSheet("""
    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: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #ccc, stop: 1 #999);
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
    QTabBar::tab:selected {
        background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                    stop: 0 #fafafa, stop: 1 #f0f0f0);
        border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #f00, stop: 1 #c00);
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
""")

27. 设置选项卡的渐变背景和圆角阴影边框

tab_widget.setStyleSheet("""
    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: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #ccc, stop: 1 #999);
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
    QTabBar::tab:selected {
        background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                    stop: 0 #fafafa, stop: 1 #f0f0f0);
        border: 1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                          stop: 0 #f00, stop: 1 #c00);
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
    }
""")

28. 设置选项卡的渐变背景和圆角阴影边框

tab_widget.setStyleSheet("""
    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: 1px solid qlineargradient(x1
http://www.dtcms.com/a/25189.html

相关文章:

  • Python----数据结构(双向链表:节点,是否为空,长度,遍历,添加,删除,查找,循环链表)
  • 伯克利 CS61A 课堂笔记 10 —— Trees
  • 阿里云ACK+GitLab企业级部署实战教程
  • 数据库配置文件
  • 【Linux网络-网络基础】TCP/IP五层(或四层)模型+网络传输的基本流程
  • DeepSeek R1:中国AI黑马的崛起与挑战
  • 外包干了3天,技术退步太明显了。。。
  • sql not in 优化
  • 【WRF模拟】全过程总结:更换不同研究时段改动总结
  • 简单易懂的金融知识:如何解读股指期货?股指期货如何做?
  • C#知识大纲回顾
  • 国产银河麒麟v10操作系统 添加epel源
  • 力扣高频sql 50题(基础版) :NULL, 表连接,子查询,case when和avg的结合
  • VirtualBox 中使用 桥接网卡 并设置 MAC 地址
  • 关于C#的一些基础知识点汇总
  • Redis 全方位解析:从入门到实战
  • sourcetree gitee 详细使用
  • vue3 配置@根路径
  • 软件工程之软件需求SWE.1
  • 工业制造能耗管理新突破,漫途MTIC-ECM平台助力企业绿色转型!
  • leaflet前端初始化项目
  • 机器学习 - 线性模型
  • Linux 内存管理与文件页缓冲区
  • 【go语言规范】 使用函数式选项 Functional Options 模式处理可选配置
  • SpringBoot整合ClickHouse数据库教程
  • 117.填充每个节点的下一个右侧节点指针Ⅱ python
  • PostgreSQL 的崛起与无服务器数据库的新时代
  • kafka集群配置操作
  • Android - Handler使用post之后,Runnable没有执行
  • 地理探测器数据准备及驱动因素分析