Display window full screen on secondary monitor using Qt

前端 未结 5 423
灰色年华
灰色年华 2020-12-14 03:07

Seems to be possible with native controls (see here and here) so now I\'m looking for some Qt code to do it.

相关标签:
5条回答
  • 2020-12-14 03:26

    One way of doing it in Qt5 is to use QWindow::setScreen to set the screen on which the window should be shown. QWidget has a windowHandle() that returns the pointer to the QWindow.

    Here is how to show your widget on second screen in full-screen mode :

    QWidget * widget = new QWidget();
    widget->show();
    widget->windowHandle()->setScreen(qApp->screens()[1]);
    widget->showFullScreen();
    
    0 讨论(0)
  • 2020-12-14 03:30

    This problem got solved while using window->showFullScreen() instead of window->show().

    0 讨论(0)
  • 2020-12-14 03:33

    I use this code for the second display in full screen successfully on both Windows & Linux

    QRect screenres = QApplication::desktop()->screenGeometry(1/*screenNumber*/);
    SecondDisplay secondDisplay = new SecondDisplay(); // Use your QWidget
    secondDisplay->move(QPoint(screenres.x(), screenres.y()));
    secondDisplay->resize(screenres.width(), screenres.height());
    secondDisplay->showFullScreen();
    
    0 讨论(0)
  • 2020-12-14 03:37

    showFullScreen first, then setGeometry.

    Qt5 tested OK

    0 讨论(0)
  • 2020-12-14 03:43

    My take on this:

      auto const desktop(QApplication::desktop());
    
      setGeometry(desktop->screenGeometry(1));
    
    #ifndef Q_OS_WIN
      setWindowState(Qt::WindowState(Qt::WindowFullScreen | windowState()));
    #endif // Q_OS_WIN
    
    0 讨论(0)
提交回复
热议问题