想实时获取到 QT ToolBar 工具栏浮动的状态,以实时调整窗体的布局。 先使用查找引擎,发现找不到什么有用的文章。 只能查 QT Help,最后获取到使用 SIGNAL topLevelChanged 可以达到目的。

于是写了如下的代码,没有使用 QT IDE 集成环境的提示(失败在这里,在自己还不熟悉 QT SIGNAL 的情况下):

connect(toolBar,SIGNAL(topLevelChanged()),this,SLOT(toolBarFloat()));

 

定义 SLOT toolBarFloat:

void MainWindow::toolBarFloat(bool topLevel)
{
    qDebug() << "toolBar floating: " << topLevel;
}

 声明 SLOT:

public slots:
    void toolBarFloat(bool topLevel);

 

都是按 SIGNAL 的原型:

void QToolBar::topLevelChanged(bool topLevel) [signal]

 运行后发现没有实现想要的目的,即没有执行 MainWindow::toolBarFloat 函数。

查来查去也没有发现什么问题,最后重写了 connect 语句,使用了 QT IDE 的提示。完成的语句如下:

connect(toolBar,SIGNAL(topLevelChanged(bool)),this,SLOT(toolBarFloat(bool)));

 拖动工具栏浮动/停靠窗体时,在“应用程序输出”窗体中终于看到如下的内容:

toolBar floating:  true
toolBar floating:  false

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2021-11-21
  • 2021-06-13
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2021-07-26
  • 2021-11-19
  • 2022-01-24
相关资源
相似解决方案