【问题标题】:Qt normal status bar not showing after temporary statusQt正常状态栏在临时状态后不显示
【发布时间】:2012-03-30 01:15:17
【问题描述】:

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

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

我明白了,当我运行我的项目时,我会收到状态 Temp 消息 3 秒。然后我就没有返回 hello world 了。 hello world 是否应该在 Temp message 位置 3 秒后自动出现?

【问题讨论】:

    标签: qt user-interface qt4 statusbar


    【解决方案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
    }
    

    【讨论】:

    • 其实我想在没有 QStatusBar::addPermanentWidget 的情况下这样做。
    【解决方案2】:

    我认为documentation 很清楚:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 2020-02-15
      • 1970-01-01
      相关资源
      最近更新 更多