c++qtstatusbarqt6qstatusbar

Modify line behind QStatusbar widgets


Is there a way to modify (remove) the line behind a permanent widget in a QStatusbar? 1

I don't know if it's important, but that's how I added the labels to the status bar:

wStyleTest::wStyleTest(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::wStyleTest)
{
    // ...

    ui->statusbar->addPermanentWidget(ui->lblPermWidget1);
    ui->statusbar->addPermanentWidget(ui->lblPermWidget2);

    // ...

Solution

  • Subclass QProxyStyle and reimplement the drawPrimitive method. In there, check for the QStyle::PE_FrameStatusBar element and return from it instead of calling the base method.

    #include <QProxyStyle>
    #include <QStyleOption>
    
    class StyleFixes : public QProxyStyle
    {
    public:
    
        void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
        {
            if (element == QStyle::PE_FrameStatusBar)
                return;
    
            QProxyStyle::drawPrimitive(element, option, painter, widget);
        }
    };
    

    Apply it to your app either in your main.cpp or constructor of MainWindow:

    QApplication::setStyle(new StyleFixes);