Maximize application on display 2 when existing
-
wrote on 20 Dec 2017, 16:32 last edited by A Former User
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 -
wrote on 20 Dec 2017, 17:20 last edited by
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 }
-
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 }
-
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 }
-
wrote on 20 Dec 2017, 22:02 last edited by
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
-
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
-
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
wrote on 21 Dec 2017, 08:21 last edited by@jpnurmi said in Maximize application on display 2 when existing:
visibility: Window.Maximized
Hello, do visibility : Window::Maximized or visibility : "Maximized"
LA -
wrote on 21 Dec 2017, 09:26 last edited by
oh no qt used is the 5.9.2 then no reason to get this error...
-
wrote on 21 Dec 2017, 16:12 last edited by
I got same error under QT 5.10...
-
wrote on 21 Dec 2017, 16:29 last edited by
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?
-
wrote on 21 Dec 2017, 16:33 last edited by
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 } } } } }
-
wrote on 21 Dec 2017, 16:35 last edited by
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...
-
wrote on 21 Dec 2017, 17:42 last edited by
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 } } } } }
-
wrote on 22 Dec 2017, 10:56 last edited by
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
-
wrote on 22 Dec 2017, 14:10 last edited by
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.
-
wrote on 22 Dec 2017, 14:20 last edited by filipdns
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
-
wrote on 22 Dec 2017, 16:41 last edited by jpnurmi
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?
-
wrote on 22 Dec 2017, 16:48 last edited by
no difference with
Component.onCompleted: screen = Qt.application.screens[0]
-
wrote on 22 Dec 2017, 17:06 last edited by
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(); }
-
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(); }
wrote on 22 Dec 2017, 17:28 last edited by filipdns@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
5/20