2012-03-13 153 views
1

正常状态消息 - 除非显示临时消息,否则这些消息始终由应用程序显示。这就是我对正常状态信息的了解。因此,使用这些代码对我的构造Qt正常状态栏在临时状态后不显示

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

我得到的是,当我运行项目中,我得到了状态临时消息,持续3秒。然后我没有拿到hello world回来。如果hello world在3秒后自动出现在的位置温度讯息

回答

1

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

尝试在“延迟初始化”时隙中执行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 
} 
+0

其实我想要没有QStatusBar :: addPermanentWidget。 – Dewsworld 2012-03-13 16:30:23

1

我觉得documentation是相当清楚的:

小部件位于最左边的第一个永久性部件 (见addPermanentWidget()),并且可以通过临时的消息变得模糊。