问题
I m using Qt5 on linux, I want to display window form fullscreen on second screen (dual monitor)? I tried this code but it doesnt work. Is there any other way?
QRect screenres = QApplication::desktop()->screenGeometry(1/*screenNumber*/);
Widget *secondDisplay = new Widget(); // Use your QWidget
secondDisplay->move(QPoint(screenres.x(), screenres.y()));
secondDisplay->resize(screenres.width(), screenres.height());
回答1:
You can use QScreen
.
QScreen *screen = QGuiApplication::screens()[1]; // specify which screen to use
SecondDisplay secondDisplay = new SecondDisplay(); // your widget
secondDisplay->move(screen->geometry().x(), screen->geometry().y());
secondDisplay->resize(screen->geometry().width(), screen->geometry().height());
secondDisplay->showFullScreen();
回答2:
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 in the last screen in full-screen mode :
secondDisplay->show();
secondDisplay->windowHandle()->setScreen(qApp->screens().last());
secondDisplay->showFullScreen();
来源:https://stackoverflow.com/questions/26803458/how-to-display-window-form-fullscreen-on-second-monitor-in-qt