QTabWidget tabPosition when using stylesheets

家住魔仙堡 提交于 2019-12-11 06:26:18

问题


I'm currently using stylesheets to theme an application. Here is the stylesheet I use for 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;
}

With this, when tabPosition is set to North or South, no problem. But with East or West, the TabBar's border is not properly styled.

Do someone know how to style a TabBar with tabPosition set to east/west?


回答1:


From the Qt stylesheet reference page:

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

So, for example, to apply your first css rule to the horizontal QTabBars:

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;
}


来源:https://stackoverflow.com/questions/7340046/qtabwidget-tabposition-when-using-stylesheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!