QLabel embedding in QStatusBar using Qt Designer

17,983

Solution 1

I don't believe so. It's fairly simple to add one programmatically, though.

If you're just wanting to show a message, you could use: statusBar()->showMessage(tr("Message Here"));, or alternatively if you really needed a QLabel on the status bar, you could do something along the lines of:

QLabel *label = new QLabel("Message");
statusBar()->addWidget(label);

label would become a child of statusBar(), and appear in the first empty spot from the bottom left (addPermanentWidget(label) would add it to the first empty spot from the bottom right). If you place QLabel label in the classes header (or other var name), you'd be able to access the variable directly later (removing the initial QLabel type from the first line, of course).

Solution 2

It is not possible with Qt Designer. I resolve it by creating label a in Qt Designer and later in constructor of my MainWindows add this line:

Ui::"class name of my MainWindows"::"name of statusBar Object"->addWidget("Object Name of Label");

In my application, the class name of mainwindows is MainWindowsForm, the status bar is named statusBar and the label is named informationLabel. Then I have:

Ui::MainWindowsForm::statusBar->addWidget(informationLabel);

Solution 3

It's not possible even if you would manually edit UI file.

Share:
17,983

Related videos on Youtube

Mohammad Sheykholeslam
Author by

Mohammad Sheykholeslam

Software/Full-Stack developer

Updated on April 20, 2022

Comments

  • Mohammad Sheykholeslam
    Mohammad Sheykholeslam about 2 years

    Is there any solution to embed a QLabel in QStatusBar using Qt Designer?

  • Mohammad Sheykholeslam
    Mohammad Sheykholeslam about 14 years
    I think it's a defect in QtDesigner
  • rbaleksandar
    rbaleksandar about 9 years
    Not a defect but a missing feature. Sadly QtDesigner is not meant for UIs, which have multi-level structure (this includes adding a QLabel to a QStatusbar etc.).
  • Sigur
    Sigur over 7 years
    How to adapt the code to use a translatable Message?
  • Kitsune
    Kitsune over 7 years
    @Sigur Any reason you're feeling like this would be significantly different from dealing with any other QLabel?
  • Sigur
    Sigur over 7 years
    Sorry. I was trying to use tr with QLabel but no success. I don't know how to use QLabel with translable text.