39

如何使我的小部件全屏显示?我试过这样的事情:

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();
}

但小部件不在系统面板之上。还有其他想法吗?

操作系统:Linux

4

2 回答 2

57

QWidget::showFullScreen()是你所需要的——多年来在我的项目中在 Linux+Windows 下工作得很好——但要小心,这个函数不应该有两次调用(例如,第一次调用QMainWindo->showFullScreen()and then MyWidget->showFullScreen())。

乔,克里斯

于 2009-08-07T20:29:20.460 回答
12

此代码将允许您通过双击设置全屏并通过再次双击返回正常视图。

void myWidget::mouseDoubleClickEvent(QMouseEvent *e) {
  QWidget::mouseDoubleClickEvent(e);
  if(isFullScreen()) {
     this->setWindowState(Qt::WindowMaximized);
  } else {
     this->setWindowState(Qt::WindowFullScreen);
  }
}
于 2012-04-25T14:59:49.450 回答