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:

    statusBar();
    
    GeneralInfo = new QLabel("[General Info]");
    GeneralInfo->setAlignment(Qt::AlignCenter);
    statusBar()->addPermanentWidget(GeneralInfo, 1);
    MeshInfo = new QLabel("");
    MeshInfo->setAlignment(Qt::AlignCenter);
    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:

    statusBar()->setMinimumWidth(width());
    

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.