Maximize application on display 2 when existing
-
See Window::screen and Qt.application.screens.
import QtQuick 2.9 import QtQuick.Window 2.3 Window { id: window visible: true // ... screen: Qt.application.screens[1] || null }
-
Looks like QTBUG-60893 which was marked fixed in Qt 5.9.1. Which version of Qt are you using?
Oh, btw, I forgot to mention that you can use Window::visibility to maximize the window:
visibility: Window.Maximized
-
I'm using stackview main qml is like that:
import QtQuick 2.9 import QtQuick.Controls 2.1 import QtQuick.Window 2.3 import QtQuick.Controls.Styles 1.1 import QtQuick.Controls 1.4 ApplicationWindow { id: window visible: true // this is mandatory visibility: Window.Maximized screen: Qt.application.screens[1] || null StackView { id: stackView //y:60 anchors.fill: parent initialItem: GardePage { header: ToolBar { width: parent.width height: 60 style: ToolBarStyle { padding { left: 8 right: 8 top: 3 bottom: 3 } background: Rectangle { gradient: Gradient { GradientStop { position: 0 ; color: "black" } GradientStop { position: 1 ; color: "green" } } } } Label { id: pageTitle text: "KARDEX DU SIA DE L'IGN " textFormat: Text.AutoText fontSizeMode: Text.VerticalFit font.pixelSize: 50 color: "lightgrey" anchors.centerIn: parent font.family: "Times New Roman" font.bold: true font.italic: true } } } } }
-
It's fine to import QtQuick.Controls 1.x and QtQuick.Controls 2.x in the same file, but only if you specify namespaces to avoid conflicts. In this particular QML file, you're not actually using QtQuick.Controls 2.x for anything. The ApplicationWindow, StackView, ToolBar, and Label types provided by QtQuick.Controls 2.x are all overridden by the QtQuick.Controls 1.x import that comes later.
The correct way to mix QQC1 and QQC2:
import QtQuick.Controls 1.x as C1 import QtQuick.Controls 2.x as C2 C2.ApplicationWindow { // ... C1.ToolBar { // ... } // ... }
How you call the namespaces is up to you, but as long as at least one of the overlapping imports has a namespace, you avoid a lot of confusion. However, I don't see anything in this file that cannot be done with Qt Quick Controls 2. The changes are minimal:
import QtQuick 2.9 import QtQuick.Controls 2.1 import QtQuick.Window 2.3 ApplicationWindow { id: window visible: true // this is mandatory visibility: Window.Maximized screen: Qt.application.screens[1] || null StackView { id: stackView anchors.fill: parent initialItem: GardePage { header: ToolBar { width: parent.width height: 60 leftPadding: 8 rightPadding: 8 topPadding: 3 bottomPadding: 3 background: Rectangle { gradient: Gradient { GradientStop { position: 0 ; color: "black" } GradientStop { position: 1 ; color: "green" } } } Label { id: pageTitle text: "KARDEX DU SIA DE L'IGN " textFormat: Text.AutoText fontSizeMode: Text.VerticalFit font.pixelSize: 50 color: "lightgrey" anchors.centerIn: parent font.family: "Times New Roman" font.bold: true font.italic: true } } } } }
-
This statement:
screen: Qt.application.screens[1] || null
means that the second screen will be set, or if not available (no such entry in the array == undefined) it assigns null instead to avoid:
Cannot assign undefined to Screen
It’s an example. Adapt it to your needs.
-
On which platform? If
screen: Qt.application.screens[0]
doesn't place the window on the primary screen, you should report a bug at bugreports.qt.io and provide details about the platform. Provide a minimal but complete runnable test case without references to anyGardePage
and others. Explain what you are doing, what you expect to happen, and what you get instead.I don't have access to a suitable environment right now to be able to test, but out of curiosity, does it make any difference if you assign the screen in
Component.onCompleted
?Window { Component.onCompleted: screen = Qt.application.screens[0] }
Also, have you inspected, what is the contents of the Qt.application.screens array, actually?
-
What about in C++?
#include <QtGui> #include <QtDebug> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QWindow window; window.resize(100, 100); window.setScreen(app.screens().value(1)); window.show(); qDebug() << "available:" << app.screens(); qDebug() << "primary:" << app.primaryScreen(); qDebug() << "window:" << window.screen(); return app.exec(); }
-
@jpnurmi debug say:
available: (QScreen(0x3923528, name="\\.\DISPLAY1"), QScreen(0x39236b0, name="\\.\DISPLAY2"))
primary: QScreen(0x3923528, name="\\.\DISPLAY1")
window: QScreen(0x3923528, name="\\.\DISPLAY1")or
available: (QScreen(0x36b0f30, name="\\.\DISPLAY1"), QScreen(0x36b1160, name="\\.\DISPLAY2"))
primary: QScreen(0x36b0f30, name="\\.\DISPLAY1")
window: QScreen(0x36b1160, name="\\.\DISPLAY2")following mouse position window: QScreen switch to DISPLAY1 or DISPLAY2
changing
window.setScreen(app.screens().value(0));
to
window.setScreen(app.screens().value(1));
nothing change