Unsolved Maximize application on display 2 when existing
-
Hello can it be possible to set the application windows to start un maximize on the desired display number 2 for example ?
Thanks for your help
Philippe -
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 }
-
@jpnurmi thank you very much!!
-
@jpnurmi I try it but I got message :
ApplicationWindow.screen" is not available due to component versioning
-
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
-
@jpnurmi oh ok, I have the 5.9.0, I go to update it then, thank you
-
@jpnurmi said in Maximize application on display 2 when existing:
visibility: Window.Maximized
Hello, do visibility : Window::Maximized or visibility : "Maximized"
LA -
oh no qt used is the 5.9.2 then no reason to get this error...
-
I got same error under QT 5.10...
-
Works for me with Qt 5.9.3 and 5.10.0. What did you import? How does the relevant part of the code look like, that you're trying to run?
-
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 } } } } }
-
you probably see I'm importing 2 QtQuick.Controls, the 1.4 and the 2.1, It's not an error, don't ask me why but some functions work with one and other with the other, 2.1 don't take all function of the 1.4...
-
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 } } } } }
-
Thank you very much.
Then now, with [1] the application start correctly on screen 2 fine, but with [0] or [2] the application start on screen were my mouse is
-
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.
-
yes understood but If I want to have 2 qt applications and force 1 in screen 1 and other on screen 2, how do that?
I try :screen: Qt.application.screens[0]
but it's not working
-
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?
-
no difference with
Component.onCompleted: screen = Qt.application.screens[0]
-
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