Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to make TabBar Labels Horizontal on Orientation West/East, but not breaking fusion Palettes?



  • Hi there..

    First of all, this Topic is linked to: this Topic, since i think it got lost.. and is still unsolved..

    I want to have the Labels of a specific TabBar being shown horizontaly, instead of verticaly.
    Therefore, i found this Code snippet here in the Forums:

    #include <QProxyStyle>
    #include <QTabBar>
    #include <QStyleOption>
    #include "tgs_globals.h"
    
    class TGS_CustomTabWest : public QProxyStyle {
    public:
        QSize sizeFromContents(ContentsType type, const QStyleOption* option,
                               const QSize& size, const QWidget* widget) const {
            QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
            if (type == QStyle::CT_TabBarTab) {
                s.transpose();
            }
            return s;
        }
    
        void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const {
            if (element == CE_TabBarTabLabel) {
                if (const QStyleOptionTab* tab = qstyleoption_cast<const QStyleOptionTab*>(option)) {
                    QStyleOptionTab opt(*tab);
                    opt.shape = QTabBar::RoundedNorth;
                    QProxyStyle::drawControl(element, &opt, painter, widget);
                    return;
                }
            }
            QProxyStyle::drawControl(element, option, painter, widget);
        }
    };
    

    posted by @MRJJ.

    The problem is, that this Snippet kills the fusion Palette colors.
    Since i applied a Darkmode Color Palette, my texts are white with a dark grey backdrop Color.

    The Color palette can be changed during runtime by changing the Color Palette from "lightPalette" to "darkPalette" and vise versa.

    The problem now, is this:
    QProxyStyle_Problem.jpg

    On the Left, the default behaviour of a QTabBar. On the Right, The horizontal Labels, as i wish them to be, but the Colors are completely broken.

    setting the Palette to the desired one, after changing the Style, is not working. setting Stylesheet after setting this Style.. not working..

    The Application should use the fusion style with custom palettes.

    I´ve no clue what @SGaist meant with "not overriding drawControl", since i´ve not done that snippet and didn´t know how to not override that things.. never used ProxyStyle before.. and this will be the only need of using ProxyStyle in the whole app.. just for this TabBar ^^".

    Perhaps, someone can help me out here..

    Ps.: TabWidget is created with QT Designer.



  • Anyone?
    T_T