25

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

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
Mohammad Sheykholeslam
  • 1,379
  • 5
  • 18
  • 35

3 Answers3

28

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).

Jonas Schnelli
  • 9,965
  • 3
  • 48
  • 60
Kitsune
  • 9,101
  • 2
  • 25
  • 24
  • How to adapt the code to use a translatable `Message`? – Sigur Nov 25 '16 at 00:24
  • @Sigur Any reason you're feeling like this would be significantly different from dealing with any other QLabel? – Kitsune Dec 22 '16 at 16:14
  • Sorry. I was trying to use `tr` with `QLabel` but no success. I don't know how to use `QLabel` with translable text. – Sigur Dec 22 '16 at 18:21
6

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);
Pierre GM
  • 19,809
  • 3
  • 56
  • 67
Joshwa
  • 61
  • 1
  • 1
5

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

delor
  • 800
  • 1
  • 7
  • 19