Dead space at bottom of QToolBar
-
I now know what changes in my code resulted in this dead space, but I don't know how to fix it.
If I use this:
constexpr int iconpixels = 48; QString styleSheet(QString( "QToolBar " "{background-color: rgba(255,255,255,205); " "border-radius: %1px;} " "QToolButton " "{max-width: %2px; " "max-height: %2px; " "border: 0px;};" ) .arg(radius). .arg(iconpixels+2) ); t.setStyleSheet(styleSheet); // t is the QToolBar
The I get the dead space.
If OTOH, I use this:
QString styleSheet(QString( "QToolBar " "{background-color: rgba(255,255,255,205); " "border-radius: %1px;};" ) .arg(radius) ); t.setStyleSheet(styleSheet);
Then I don't get the dead space and tool bar looks like this:
-
I guess you call
adjustSize
beforesetStyleSheet
.
adjustSize
will resize the widget to its size hint. But the size hint changes after you set style sheet. So you should call it after that.
You know what, replaceadjustSize()
withlayout()->setSizeConstraint(QLayout::SetFixedSize)
, then you don't need to worry about when to call it.
Also, since you end up subclassing the QToolBar but don't seem to need the QToolBar functions, how about subclassing a normal QWidget with 4 QToolButtons in its QVBoxLayout?
(The tool buttons should be set to auto raise.)
I think that kind of ui will be easier to customize than a toolbar. -
I've come to the conclusion that this was just going round in circles as setting the stylesheet changed the parameters for adjustSize(). Problem is that if I called adjustSize after setting the style, I lost the nice rounded corners even though the style asks for them.
So I've just removed the styling of the ToolButtons and accepted the version that uses the translucent blue/grey rectangles as hints, which is close enough to what the original Windows custom control looked like.
Thanks again for your help @Bonnie