39

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

Termininja
  • 6,620
  • 12
  • 48
  • 49
Max Frai
  • 61,946
  • 78
  • 197
  • 306

2 Answers2

57

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()).

ciao, Chris

3DH
  • 1,461
  • 11
  • 11
  • 4
    Unless "MyWidget" is another window MyWidget->showFullScreen() won't do anything. – Graphics Noob Aug 07 '09 at 23:18
  • how about multiple screen setups with XRandr,Eyefinity or Xinerama? Does this work properly? – drahnr Mar 21 '10 at 20:34
  • multiple screens should work - but by default showFullscreen() only uses one screen - but you can determine the whole desktop size (inluding multiple monitors/screens) and set the geometry manually... – 3DH Apr 06 '10 at 18:59
  • Fullscreen works but i have a white frame around my window - how can i remove it? – stach Nov 17 '10 at 20:59
  • Normally you don't have a frame - only if the widget (QFrame or derived class) which called showFullScreen() has a FrameStyle != NoFrame, then you'll see a frame... so just check your fullscreen widget end ensure that you don't have, for example a QLabel with a frame. – 3DH Nov 27 '10 at 22:34
  • 1
    The white frame in my case came from a border in the layout manager used in the central widget. Removed it with - layout->setContentsMargins(0,0,0,0); – whatnick May 13 '13 at 08:18
12

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);
  }
}
Sputnik
  • 168
  • 2
  • 7