[英]Qt connect are not working when window is in fullscreen mode
I have got problem with some connection: 我有一些连接问题:
QAction* fs = new QAction(this);
fs->setShortcut(Qt::Key_F);
connect(fs, &QAction::triggered, this, &MainWindow::fullscreen);
menuBar()->addAction(fs);
And the fullscreen function is: 全屏功能是:
if(!fullscreenMode)
{
mouseMoved=time(0);
this->menuBar()->hide();
this->showFullScreen();
fullscreenMode=true;
}
else
{
this->menuBar()->show();
timeBar->show();
controlBar->show();
this->showNormal();
fullscreenMode=false;
timeBar->visibilityChanged(true);
controlBar->visibilityChanged(true);
}
I can't get back to normal mode using shortcut ( F button), but I can do it using double click which is using the same function. 我无法使用快捷键(F按钮)返回到正常模式,但是可以使用具有相同功能的双击来做到这一点。 Where is my mistake?
我的错误在哪里?
答案是:
QShortcut* fullscreenShortcut = new QShortcut(QKeySequence(Qt::Key_F),this,SLOT(fullscreen()));
Have "fullscreenMode" been initialized when the MainWindow is created? 创建MainWindow时是否已初始化“ fullscreenMode”?
Here comes 2 problems : 这里有两个问题:
undefined fullscreenMode cause unexpected result. 未定义的fullscreenMode导致意外结果。
QAction triggered pass a boolean parameter, if your function - "fullscreen" has a parameter too, the "fullscreen" will catch this parameter which pass from triggered(). QAction触发传递了一个布尔参数,如果您的函数-“ fullscreen”也有一个参数,则“ fullscreen”将捕获此参数,该参数是从Triggered()传递过来的。 Also , if the action is checkable, the boolean parameter is true if the action is checked, or false if the action is unchecked.
另外,如果该动作是可检查的,则布尔参数如果选中该动作,则为true;如果未选中该动作,则为false。
Hope these can help. 希望这些可以有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.