How to add back a removed widget by removeWidget() from a QStatusBar?

68 Views Asked by At

I have read the QStatusBar class Documentation, and it is says that removeWidget():

does not delete the widget but hides it. To add the widget again, you must call both the addWidget() and show() functions.

As per the instructions, I wrote the code below:

ui->statusbar->addWidget(ui->label);
ui->statusbar->removeWidget(ui->label);
ui->statusbar->addWidget(ui->label);
ui->statusbar->show();

I added label widget using Qt Designer.

I was Expecting that label will be added to the statusbar but it was not.

How to do I add it back to statusbar?

1

There are 1 best solutions below

0
HiFile.app - best file manager On

You should call

ui->label->show()

instead of:

ui->statusbar->show()

As follows:

ui->statusbar->addWidget(ui->label);
ui->statusbar->removeWidget(ui->label);
ui->statusbar->addWidget(ui->label);
ui->label->show();