Linux 全屏小部件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1246825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fullscreen widget
提问by Max Frai
How can I make my widget fullscreen? I've tried something like this:
如何使我的小部件全屏显示?我试过这样的事情:
void MainWindow::SetFullScreen()
{
// Make our window without panels
this->setWindowFlags( Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint );
// Resize refer to desktop
this->resize( QApplication::desktop()->size() );
this->setFocusPolicy( Qt::StrongFocus );
this->setAttribute(Qt::WA_QuitOnClose, true);
qApp->processEvents();
show();
this->setFocus();
}
But widget isn't over system panels. Any another ideas?
但是小部件不在系统面板上。还有其他想法吗?
OS: Linux
操作系统:Linux
采纳答案by 3DH
QWidget::showFullScreen()
is what you need - works great under Linux+Windows in my projects for years - but be careful, there shouldn't be two calls of this function (eg. first call of QMainWindo->showFullScreen()
and then MyWidget->showFullScreen()
).
QWidget::showFullScreen()
是您所需要的 - 在我的项目中在 Linux+Windows 下运行良好多年 - 但要小心,不应有两次调用此函数(例如,第一次调用 ,QMainWindo->showFullScreen()
然后MyWidget->showFullScreen()
)。
ciao, Chris
乔,克里斯
回答by Sputnik
This code will allow you to set a full screen by double clicking and to return back to the normal view by double clicking again.
此代码将允许您通过双击设置全屏,并通过再次双击返回到正常视图。
void myWidget::mouseDoubleClickEvent(QMouseEvent *e) {
QWidget::mouseDoubleClickEvent(e);
if(isFullScreen()) {
this->setWindowState(Qt::WindowMaximized);
} else {
this->setWindowState(Qt::WindowFullScreen);
}
}