ColinDuquesnoy / QDarkStyleSheet

A dark style sheet for QtWidgets application
Other
2.76k stars 726 forks source link

QToolbar background #296

Open giallu opened 2 years ago

giallu commented 2 years ago

I am working on a Qt\C++ desktop application, and having a bit of a trouble with the dark theme in a QToolbar I am using to display additional controls over another widget. Basically, while the stock theme has a transparent background, here there is a solid one so the result is cumbersome.

This is the default theme: image

While this is what happens switching to dark theme: image

The toolbar is composed by 4 icons and a spacer on the left side (that is used to right align the icons). Icons are trasparent too, so I think a correct styling is also missing on QAction.

huseyinkozan commented 2 years ago

Hi, As a workaround, I am using transparent widget.

    QWidget * expander3 = new QWidget(this);
    expander3->setObjectName("expander3");
    expander3->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    expander3->setStyleSheet("background-color:transparent");
    ui->mainToolBar->insertWidget(ui->actionSettings, expander3);
giallu commented 2 years ago

I ended up doing the same, but I hope this is changed in the theme.

epasveer commented 4 months ago

Found this old post. And the work around worked for me.

In my project, I too divided the QToolBar with buttons on the left and a couple on the right, with a spacer between. This spacer inherits the wrong background color. Because it's just a QWidget. The style sheet can't change QWidget as it would change more than just the QToolBar.

The only solution I see is if Qt introduced a new object called QToolBarSpacer. StyleSheets can then provide a style for that object that then matches QToolBar. However, I can't see it happening.

Bad: image

Good: image

giallu commented 4 months ago

The only solution I see is if Qt introduced a new object called QToolBarSpacer. StyleSheets can then provide a style for that object that then matches QToolBar. However, I can't see it happening.

Not necessarily, in fact I recently styled some QToolButtons in my interface that needed a custom background by applying them a specific CSS class like this:

    b = new QToolButton(this);
    b->setProperty("class", "model");
    statusBar()->addPermanentWidget(b);

And then appending this to the stylesheet (loaded in the QString s):

// add custom style for model buttons
    s += "QToolButton[class=\"model\"]:checked { border: 1px solid #8f8f91; border-radius: 6px; background-color: #148cd2; }";
    qApp->setStyleSheet(s);
epasveer commented 4 months ago

It's not the styling of the QToolButton's themselves. It's the lack of styling on the spacer widget between them. As in @huseyinkozan workaround example.

I ended up doing the same, but I hope this is changed in the theme.

I don't know how this (or any style) can handle this. I could be wrong, though.

Anyway, I'm happy with @huseyinkozan workaround.