Search code examples
c++qtqt-designer

Set text for statusbar in QtDesigner?


By default, if I create a new Form in QtDesigner, of type "Main Window", I get three elements in there: centralwidget, menubar - which is not visible in Preview (Ctrl-R), unless actual menu entries are added; and statusbar.

The problem is - by default, the statusbar is the same background color as the rest, and so, when I do a Preview, I cannot really perceive whether the statusbar is there or not:

qtdesigner

Basically, the only thing I can see is the "sizeGrip", which is not always easy to see - so I would like to have a text/message shown in the statusbar as well.

Now, I know that the API for QStatusBar Class has .showMessage used to show text in a statusbar - however, I cannot find any similar field in QtDesigner?!

So - is it possible to set a default/placeholder text in the statusbar in QtDesigner - and if so, how?


Solution

  • No, you cannot.

    In QtDesigner, you can only set properties of a widget (see Q_PROPERTY), not invoke methods. The properties are listed in the Properties section of the documentation, and QStatusBar only has sizeGripEnabled (and the inherited properties from QWidget)

    But what is the actual problem? You cannot clearly make out the status bar in the preview? The preview is supposed to help in checking singal/slots and layout constraints, not as a full functioning application.

    There are also things that will influence the actual look&feel in the final application that cannot be checked in designer preview, like dynamic stylesheets, or custom styles.


    if you want to check how your window looks like with text in the statusbar, you will need to make a mock-application that does just this: show some text

    #include <QtCore>
    #include <QtWidgets>
    #include "ui_mainwindow.h"
    
    int main(int argc, char **argv) {
        QApplication app(argc, argv);
        Ui::MainWindow ui;
        QMainWindow wnd;
        ui.setupUi(&wnd);
        wnd.show();
        ui.statusbar->showMessage("Hello World!");
        return app.exec();
    }