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. QML application on second monitor in Ubuntu
Qt 6.11 is out! See what's new in the release blog

QML application on second monitor in Ubuntu

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 2.7k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    PouryaTorabi
    wrote on last edited by
    #1

    Hi,
    I have written an application with qml and I want it to start in my second monitor, I used this:

    ApplicationWindow {
        id: mainAppWindow
        visible: true
        visibility : Window.FullScreen
        minimumWidth: 700
        minimumHeight: 350
        screen: {
            for (var i = Qt.application.screens.length-1;i>=0;i--){
                if (Qt.application.screens[i].width !== 2560){
                    print(i)
                    print(Qt.application.screens[i].width)
                    mainAppWindow.screen = Qt.application.screens[i]
    
                    break
                }
            }
        }
    }
    

    It works well in windows but when I compile it in Ubuntu environment, it shows the app in my first monitor.

    1 Reply Last reply
    0
    • CKurduC Offline
      CKurduC Offline
      CKurdu
      wrote on last edited by
      #2

      Hi PouryaTorabi ,
      I don't know the exact reason but I can solve the problem as below.

      ApplicationWindow {
          id: mainAppWindow
          visible: true
          visibility : Window.FullScreen
          minimumWidth: 700
          minimumHeight: 350
          Component.onCompeleted: {
              for (var i = Qt.application.screens.length-1;i>=0;i--){
                  if (Qt.application.screens[i].width !== 2560){
                      print(i)
                      print(Qt.application.screens[i].width)
                      x= Qt.application.screens[i].virtualX;
                      y= Qt.application.screens[i].virtualY;
                     
                      //you don't need below code
                      //mainAppWindow.screen = Qt.application.screens[i]
      
                      break
                  }
              }
          }
      }
      

      I wish these codes help you.

      You reap what you sow it

      P 1 Reply Last reply
      1
      • CKurduC CKurdu

        Hi PouryaTorabi ,
        I don't know the exact reason but I can solve the problem as below.

        ApplicationWindow {
            id: mainAppWindow
            visible: true
            visibility : Window.FullScreen
            minimumWidth: 700
            minimumHeight: 350
            Component.onCompeleted: {
                for (var i = Qt.application.screens.length-1;i>=0;i--){
                    if (Qt.application.screens[i].width !== 2560){
                        print(i)
                        print(Qt.application.screens[i].width)
                        x= Qt.application.screens[i].virtualX;
                        y= Qt.application.screens[i].virtualY;
                       
                        //you don't need below code
                        //mainAppWindow.screen = Qt.application.screens[i]
        
                        break
                    }
                }
            }
        }
        

        I wish these codes help you.

        P Offline
        P Offline
        PouryaTorabi
        wrote on last edited by
        #3

        @CKurdu Yes that did help me. There was just a problem that the application would splash in the main window and then would go to the second window. Here is my complete code if any one needed, Thank for your help:

        ApplicationWindow {
            id: mainAppWindow
            visible: false
            minimumWidth: 700
            minimumHeight: 350
            Component.onCompeleted: {
                for (var i = Qt.application.screens.length-1;i>=0;i--){
                    if (Qt.application.screens[i].width !== 2560){
                        print(i)
                        print(Qt.application.screens[i].width)
                        x= Qt.application.screens[i].virtualX;
                        y= Qt.application.screens[i].virtualY;
                        visible = true
                        visibility = Window.FullScreen
        
                        break
                    }
                }
            }
        }
        

        First i changed the visibility to false and then changed it to true after the screen was set.

        1 Reply Last reply
        1

        • Login

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