Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.4.2, 6.4.3, 6.5.0
-
None
Description
The spacing between buttons of the class inherited from the QToolBar can't be controlled through the stylesheets when it has been already defined for QToolBar class.
Having stylesheet with next code:
QToolBar{ spacing: 2px;} CustomToolBar{ spacing: 20px; background: white;}
produces the next result:
Both toolbars have spacing equal to 2px despite that it is set to 20px for objects CustomToolBar class. At the same time, the background is correctly set to white.
The problem could be that QToolBarLayout::updateMarginAndSpacing() is called before render rules for CustomToolBar are initialized.
A temporary workaround could be sending StyleChange event to the custom toolbar after handling Polish event.
bool CustomToolBar::event(QEvent* event) { // Code fixing the issue const bool res = QToolBar::event(event); #if 1 if (event->type() == QEvent::Polish) { QEvent e(QEvent::StyleChange); QCoreApplication::sendEvent(this, &e); } #endif return res; }
Results after applying the fix
The minimal project reproducing the bug is attached.
Also if style of the class has a dynamic property then QToolBarLayout::updateMarginAndSpacing() needs to be called after the change of that property:
CustomToolBar[CustomProperty=true]
{
spacing: 20px;
background: yellow;
}