Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Dead space at bottom of QToolBar



  • My toolbar has unnecessary space at the bottom below the last tool button:

    fdbe6745-fbdd-4763-9940-ef053e6ea368-image.png

    How to get rid?



  • 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:

    1dc8baa2-39b7-47be-8e2c-53bfa8a18952-image.png



  • I guess you call adjustSize before setStyleSheet.
    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, replace adjustSize() with layout()->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


Log in to reply