Qt正常状态栏在临时状态后不显示

Qt正常状态栏在临时状态后不显示,qt,user-interface,qt4,statusbar,Qt,User Interface,Qt4,Statusbar,正常状态消息-除非显示临时消息,否则这些消息始终由应用程序显示。这是我对正常状态消息的了解。所以在我的构造函数上使用这些代码 ui.statusbar->showMessage("Temp message", 3000); // ui is the Ui::AutoGenHeaderForForm QLabel *label = new QLabel; ui.statusBar->addWidget(label); label->setText("hello world");

正常状态消息-除非显示临时消息,否则这些消息始终由应用程序显示。这是我对正常状态消息的了解。所以在我的构造函数上使用这些代码

ui.statusbar->showMessage("Temp message", 3000); // ui is the Ui::AutoGenHeaderForForm
QLabel *label = new QLabel;
ui.statusBar->addWidget(label);
label->setText("hello world");

我明白了,当我运行我的项目时,我得到了持续3秒的状态Temp消息。那我就不会再回《你好世界》。如果hello world在3秒后自动出现在Temp message的位置?

假设您显示的代码在主窗口的构造函数中,则问题可能是由于未正确处理事件,因为在主窗口创建时事件循环尚未启动

尝试在“延迟初始化”插槽中执行
showMessage
,例如:

QLabel *label = new QLabel;
ui.statusBar->addWidget(label);
label->setText("hello world");
QTimer::singleShot ( 0, this, SLOT(delayedInit() );

void MainWindow::delayedInit()
{
    ui.statusbar->showMessage("Temp message", 3000); // ui is the Ui::AutoGenHeaderForForm
}
我认为问题很清楚:

小部件位于第一个永久小部件的最左侧 (请参阅addPermanentWidget())并可能被临时消息遮挡


实际上,我想在没有QStatusBar::addPermanentWidget的情况下完成它。