Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QToolbar background #296

Open
giallu opened this issue Oct 28, 2021 · 5 comments
Open

QToolbar background #296

giallu opened this issue Oct 28, 2021 · 5 comments

Comments

@giallu
Copy link

giallu commented Oct 28, 2021

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
Copy link

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
Copy link
Author

giallu commented Jan 4, 2022

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

@epasveer
Copy link

epasveer commented Mar 3, 2024

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
Copy link
Author

giallu commented Mar 4, 2024

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
Copy link

epasveer commented Mar 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants