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. QMainWindow opens in the screen where the mouse is currently in
Forum Updated to NodeBB v4.3 + New Features

QMainWindow opens in the screen where the mouse is currently in

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 1.5k Views 3 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by Mark81
    #1

    I noticed that when I launch a QMainWindow application (it might be the same with a simple QWidget) it opens in the screen where the mouse is in that moment. Of course, if you have multiple screens.

    This is not a standard Windows behavior, other applications seem not to follow this rule. Sometimes it's annoying... is there anything that we can disable?

    raven-worxR J.HilkJ 2 Replies Last reply
    0
    • M Mark81

      I noticed that when I launch a QMainWindow application (it might be the same with a simple QWidget) it opens in the screen where the mouse is in that moment. Of course, if you have multiple screens.

      This is not a standard Windows behavior, other applications seem not to follow this rule. Sometimes it's annoying... is there anything that we can disable?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Mark81 said in QMainWindow opens in the screen where the mouse is currently in:

      This is not a standard Windows behavior, other applications seem not to follow this rule

      i saw quite some applications which behave this way actually.
      Why should it exactly spawn in a particular position?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @raven-worx Well, why it should not? :-) I find very annoying that it spawns here or there where it finds my mouse in that moment... Anyway, I understand these are just opinions. The question is if there's a way to change the default beahvior.

        1 Reply Last reply
        0
        • M Mark81

          I noticed that when I launch a QMainWindow application (it might be the same with a simple QWidget) it opens in the screen where the mouse is in that moment. Of course, if you have multiple screens.

          This is not a standard Windows behavior, other applications seem not to follow this rule. Sometimes it's annoying... is there anything that we can disable?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Mark81

          //Constructor
          
          {
               ....
              QMetaObject::invokeMethod(this, &MainWindow::afterStartup,Qt::QueuedConnection);
          }
          
          MainWindow::afterStartup()
          {
              auto screens = QApplication::screens();
              
              if(screens.size() >1) {
                  //more than 1 scrren, move window whereever you want it to
                  move( x, y);
              }
          }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          kshegunovK 1 Reply Last reply
          4
          • J.HilkJ J.Hilk

            @Mark81

            //Constructor
            
            {
                 ....
                QMetaObject::invokeMethod(this, &MainWindow::afterStartup,Qt::QueuedConnection);
            }
            
            MainWindow::afterStartup()
            {
                auto screens = QApplication::screens();
                
                if(screens.size() >1) {
                    //more than 1 scrren, move window whereever you want it to
                    move( x, y);
                }
            }
            
            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            You can do that after the object's become valid, there's no need to queue it through the event loop.

            Read and abide by the Qt Code of Conduct

            J.HilkJ 1 Reply Last reply
            1
            • kshegunovK kshegunov

              You can do that after the object's become valid, there's no need to queue it through the event loop.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @kshegunov
              this is just from the top of my head. I don't know when or where the Object becomes valid, without looking it further up. So I simply queued it to be sure, that it's after the complete setup


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              kshegunovK 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @kshegunov
                this is just from the top of my head. I don't know when or where the Object becomes valid, without looking it further up. So I simply queued it to be sure, that it's after the complete setup

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @J.Hilk said in QMainWindow opens in the screen where the mouse is currently in:

                this is just from the top of my head. I don't know when or where the Object becomes valid, without looking it further up. So I simply queued it to be sure, that it's after the complete setup

                Not an error, just sayin'.

                Read and abide by the Qt Code of Conduct

                G 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  @J.Hilk said in QMainWindow opens in the screen where the mouse is currently in:

                  this is just from the top of my head. I don't know when or where the Object becomes valid, without looking it further up. So I simply queued it to be sure, that it's after the complete setup

                  Not an error, just sayin'.

                  G Offline
                  G Offline
                  Go Fish
                  wrote on last edited by Go Fish
                  #8

                  It is an error from consumer POV, because it does that even if instructed not to, if originally was instrcted to be open on "main" screen. Worse, using Qt functionality to open Window on particular display is ignored for display "0.0" .

                  Funny, that after this numbering of screens for app changes. If several applications are started, each got screen number 0 as they were launched on.

                  Imagine a multiscreen setup where several windows have to be opened on separate screens. It's a hardware monitoring station, after clicking the icon. I encounter this effect since Qt 4.8.7 that QMainWindow always jumps to the mouse's location, on Xorg only.

                  A "hack" to put start icon on right screen doesn't work because user is able to move cursor faster than app is launched.

                  Neither Windows nor Wayland behavour offer the same, so I supect that X11 window managers are the culprit.

                  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