Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set the default monitor for applicaiton window.
Qt 6.11 is out! See what's new in the release blog

How to set the default monitor for applicaiton window.

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 3.8k Views 2 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by
    #1

    I have a three monitor setup. Whenever I run my QT application the application window always shows up on the left hand monitor. I am not sure why it does this. I have tried changing my primary monitor and it still shows up on the left monitor. Is anyone aware of a setting for this in QT creator? I could not seem to find one.

    Pl45m4P 1 Reply Last reply
    0
    • C Circuits

      I have a three monitor setup. Whenever I run my QT application the application window always shows up on the left hand monitor. I am not sure why it does this. I have tried changing my primary monitor and it still shows up on the left monitor. Is anyone aware of a setting for this in QT creator? I could not seem to find one.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Circuits said in How to set the default monitor for applicaiton window.:

      I am not sure why it does this.

      Probably because the desktop coordinate system starts top left with (0, 0).

      See:

      • https://doc.qt.io/qt-5/qscreen.html

      Get primaryScreen:

      • https://doc.qt.io/qt-5/qguiapplication.html#primaryScreen-prop

      List all detected/available screens:

      • https://doc.qt.io/qt-5/qguiapplication.html#screens

      You could specify in your main.cpp where your first app window should be displayed initially.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      HowardHarknessH 1 Reply Last reply
      3
      • Pl45m4P Pl45m4

        @Circuits said in How to set the default monitor for applicaiton window.:

        I am not sure why it does this.

        Probably because the desktop coordinate system starts top left with (0, 0).

        See:

        • https://doc.qt.io/qt-5/qscreen.html

        Get primaryScreen:

        • https://doc.qt.io/qt-5/qguiapplication.html#primaryScreen-prop

        List all detected/available screens:

        • https://doc.qt.io/qt-5/qguiapplication.html#screens

        You could specify in your main.cpp where your first app window should be displayed initially.

        HowardHarknessH Offline
        HowardHarknessH Offline
        HowardHarkness
        wrote on last edited by
        #3

        @Pl45m4 said in How to set the default monitor for application window.:

        You could specify in your main.cpp where your first app window should be displayed initially.

        How? The primaryScreen member is defined as:

        Q_PROPERTY(QScreen *primaryScreen READ primaryScreen NOTIFY primaryScreenChanged STORED false)
        

        I could not find any "setter" function. I gather that I have to generate a "signal" somehow (to "notify" the primaryScreenChanged), but I'm a relative noob on Qt, and I'm not sure how to do that.

        The reason I chimed in on this thread is that I have a similar problem -- except that when I run my application, it seems to sometimes randomly pick one of my 3 monitors. It's usually the monitor on which I have the IDE open, but not always.

        Ideally, I would like to get a list of the monitors (QGuiApplication::screens()), and pick one that has a screen resolution of 1920x1080 and a 100% scale. I'd settle for just setting the 1920x1080 screen as my main screen.

        I'm using Qt 5.14 (customer requirement) and MinGW 32-bit C++.

        Howard Lee Harkness
        https://howardleeharkness.com/resume
        Current contract ends on March 11th, 2022 -- Looking for C++ Real-time Embedded Systems work

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Untested: QWidget::windowHandle() and then QWindow::setScreen() on your MainWindow in main.cpp

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          HowardHarknessH 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            Untested: QWidget::windowHandle() and then QWindow::setScreen() on your MainWindow in main.cpp

            HowardHarknessH Offline
            HowardHarknessH Offline
            HowardHarkness
            wrote on last edited by
            #5

            @Christian-Ehrlicher Thank you! I think I now have enough information. I'll give that a try today.

            Howard Lee Harkness
            https://howardleeharkness.com/resume
            Current contract ends on March 11th, 2022 -- Looking for C++ Real-time Embedded Systems work

            Pl45m4P C 2 Replies Last reply
            0
            • HowardHarknessH HowardHarkness

              @Christian-Ehrlicher Thank you! I think I now have enough information. I'll give that a try today.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by Pl45m4
              #6

              @HowardHarkness

              Or you work with your available screen geometry by setting/moving the widget to coordinates which are on the desired screen. This might require some calculations to be immune to resolution changes etc.
              But you can get the geometry of every screen from QScreen.
              Say, you have 1920x1080 + 1920x1080 (both 100%), then (1921, 0) must be top left point on second screen..
              [ also not tested ;-) ]


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • HowardHarknessH HowardHarkness

                @Christian-Ehrlicher Thank you! I think I now have enough information. I'll give that a try today.

                C Offline
                C Offline
                Circuits
                wrote on last edited by
                #7

                @HowardHarkness Any luck with this?

                HowardHarknessH 1 Reply Last reply
                0
                • C Circuits

                  @HowardHarkness Any luck with this?

                  HowardHarknessH Offline
                  HowardHarknessH Offline
                  HowardHarkness
                  wrote on last edited by
                  #8

                  @Circuits said in How to set the default monitor for applicaiton window.:

                  @HowardHarkness Any luck with this?

                  My contract ended, and I never got to try it. It was just too far down on the list of things I had to finish. I had a lot of last-minute corrections to various errors I made :)

                  Howard Lee Harkness
                  https://howardleeharkness.com/resume
                  Current contract ends on March 11th, 2022 -- Looking for C++ Real-time Embedded Systems work

                  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