使用样式表时的 QTabWidget tabPosition

标签 qt stylesheet qtabwidget qtabbar

我目前正在使用样式表来为应用程序设置主题。 这是我用于 QTabWidget 的样式表:

/*QTabBar et QTabWidget*/
QTabBar::tab {
    background: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(73, 73, 74, 255), stop:1 rgba(40, 40, 40, 255));
    border: 1px solid rgb(190, 190, 190);
    max-height: 0.6em;
    min-width: 0.6em;
    padding: 5px;
    margin-left: -1px;
    margin-right: -1px;
}
QTabBar::tab:selected, QTabBar::tab:hover {
    background: qlineargradient(spread:pad, x1:0.5, y1:1, x2:0.5, y2:0, stop:0 rgba(39, 117, 219, 255), stop:1 rgba(107, 171, 249, 255));
}


QTabBar::tab:last {
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
    margin-right: 0px;
}

QTabBar::tab:first {
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
    margin-left: 0px;
}

QTabBar::tab:only-one {
    border-radius: 3px;
    margin: 0px;
}

有了这个,当 tabPosition 设置为 North 或 South 时,没问题。但是对于 East 或 West,TabBar 的边框样式不正确。

有人知道如何设置 tabPosition 设置为东/西的 TabBar 样式吗?

最佳答案

来自Qt stylesheet reference page :

The :top, :left, :right, :bottom pseudo states depending on the orientation of the tabs.

因此,例如,将您的第一个 css 规则应用于水平 QTabBar:

QTabBar::tab:top, QTabBar::tab:bottom {
    background: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(73, 73, 74, 255), stop:1 rgba(40, 40, 40, 255));
    border: 1px solid rgb(190, 190, 190);
    max-height: 0.6em;
    min-width: 0.6em;
    padding: 5px;
    margin-left: -1px;
    margin-right: -1px;
}

关于使用样式表时的 QTabWidget tabPosition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7340046/

相关文章:

html - 适合显示静态 html 页面的 C++ 小部件

c++ - 尝试将小部件添加到 QTabWidget 时出错

c++ - 同时滚动不同的 Widget

css - Rails - CSS 未在 Internet Explorer 中加载

css - 统一不同版本的页面样式表并比较覆盖

html - 无法将我的 CSS 链接到我的 HTML

qt - 在 QTabWidget 选项卡中设置标签文本

c++ - QTabWidget里面的QTableView不显示数据

c++ - Qt中的透明窗口

c++ - Qt QFile 和 OpenGL ES 2.0 顶点着色器意外的文件结尾