Nominate our 2022 Qt Champions!

Width of QStatusBar

  • I'm wondering how to change the width of my QStatusBar such that it has the same width as my QMainWindow (which contains a Horizontal Layout using certain margins, might be relevant to mention this).

    Part of the code:

    GeneralInfo = new QLabel("[General Info]");
    statusBar()->addPermanentWidget(GeneralInfo, 1);
    MeshInfo = new QLabel("");
    statusBar()->addPermanentWidget(MeshInfo, 1);
    statusBar()->setStyleSheet(QString("margin-right: 0px; padding: 6px;"));

    Result (at runtime):

    I get similar results when leaving out the last line of code (using the style sheet). When maximizing the window, the width of the QStatusBar is correct (with or without the code shown above).

    One other attempt to solve the issue:


    Here, width() returns the width of my QMainWindow. No luck though. Any ideas?

  • Moderators

    The corner space is occupied by a resize handle. It's not visible in your theme but you can use this stylesheet to see it clearly:

    statusBar()->setStyleSheet("margin-right: 0px; padding: 6px; border: 1px solid red;");

    Maximized window has no resize handle so that's why the issue goes away.
    If you don't want the resize handle you can disable it with statusBar()->setSizeGripEnabled(false);.

  • Thanks! Problem solved :).

Log in to reply