Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Maximize application on display 2 when existing
QtWS25 Last Chance

Maximize application on display 2 when existing

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
20 Posts 3 Posters 4.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    filipdns
    wrote on last edited by A Former User
    #1

    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

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2

      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
      }
      
      F 2 Replies Last reply
      3
      • jpnurmiJ jpnurmi

        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
        }
        
        F Offline
        F Offline
        filipdns
        wrote on last edited by
        #3

        @jpnurmi thank you very much!!

        1 Reply Last reply
        1
        • jpnurmiJ jpnurmi

          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
          }
          
          F Offline
          F Offline
          filipdns
          wrote on last edited by
          #4

          @jpnurmi I try it but I got message :

          ApplicationWindow.screen" is not available due to component versioning

          1 Reply Last reply
          0
          • jpnurmiJ Offline
            jpnurmiJ Offline
            jpnurmi
            wrote on last edited by
            #5

            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
            
            F ODБOïO 2 Replies Last reply
            2
            • jpnurmiJ jpnurmi

              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
              
              F Offline
              F Offline
              filipdns
              wrote on last edited by
              #6

              @jpnurmi oh ok, I have the 5.9.0, I go to update it then, thank you

              1 Reply Last reply
              0
              • jpnurmiJ jpnurmi

                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
                
                ODБOïO Offline
                ODБOïO Offline
                ODБOï
                wrote on last edited by
                #7

                @jpnurmi said in Maximize application on display 2 when existing:

                visibility: Window.Maximized

                Hello, do visibility : Window::Maximized or visibility : "Maximized"
                LA

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  filipdns
                  wrote on last edited by
                  #8

                  oh no qt used is the 5.9.2 then no reason to get this error...

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    filipdns
                    wrote on last edited by
                    #9

                    I got same error under QT 5.10...

                    1 Reply Last reply
                    0
                    • jpnurmiJ Offline
                      jpnurmiJ Offline
                      jpnurmi
                      wrote on last edited by
                      #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?

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        filipdns
                        wrote on last edited by
                        #11

                        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
                        
                                        }
                                    }
                                }
                            }
                        }
                        
                        1 Reply Last reply
                        0
                        • F Offline
                          F Offline
                          filipdns
                          wrote on last edited by
                          #12

                          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...

                          1 Reply Last reply
                          0
                          • jpnurmiJ Offline
                            jpnurmiJ Offline
                            jpnurmi
                            wrote on last edited by
                            #13

                            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
                                            }
                                        }
                                    }
                                }
                            }
                            
                            1 Reply Last reply
                            1
                            • F Offline
                              F Offline
                              filipdns
                              wrote on last edited by
                              #14

                              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

                              1 Reply Last reply
                              0
                              • jpnurmiJ Offline
                                jpnurmiJ Offline
                                jpnurmi
                                wrote on last edited by
                                #15

                                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.

                                1 Reply Last reply
                                0
                                • F Offline
                                  F Offline
                                  filipdns
                                  wrote on last edited by filipdns
                                  #16

                                  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

                                  1 Reply Last reply
                                  0
                                  • jpnurmiJ Offline
                                    jpnurmiJ Offline
                                    jpnurmi
                                    wrote on last edited by jpnurmi
                                    #17

                                    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 any GardePage 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?

                                    1 Reply Last reply
                                    0
                                    • F Offline
                                      F Offline
                                      filipdns
                                      wrote on last edited by
                                      #18

                                      no difference with

                                      Component.onCompleted: screen = Qt.application.screens[0]
                                      
                                      1 Reply Last reply
                                      0
                                      • jpnurmiJ Offline
                                        jpnurmiJ Offline
                                        jpnurmi
                                        wrote on last edited by
                                        #19

                                        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();
                                        }
                                        
                                        F 1 Reply Last reply
                                        0
                                        • jpnurmiJ jpnurmi

                                          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();
                                          }
                                          
                                          F Offline
                                          F Offline
                                          filipdns
                                          wrote on last edited by filipdns
                                          #20

                                          @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

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved