Open giallu opened 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);
I ended up doing the same, but I hope this is changed in the theme.
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:
Good:
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);
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.
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](https://user-images.githubusercontent.com/6527/139270001-55b6fa04-0dc0-4167-9440-eb773a35deed.png)
While this is what happens switching to dark theme:![image](https://user-images.githubusercontent.com/6527/139270331-a5dd1ba5-403f-4573-b0e0-ce7d796daddb.png)
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.