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. Notification when application changes to new screen
Forum Update on Monday, May 27th 2025

Notification when application changes to new screen

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 4 Posters 3.3k 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.
  • A Offline
    A Offline
    antiocles
    wrote on last edited by
    #1

    Hello,

    I am implementing a multi screen application on desktop. Some screens may be restricted vertically, so I plan to adjust the UI as needed when the application is either manually moved by the user to a different screen, or I programmatically put that screen onto the smaller window.

    I can bind to the Screen.height variable or Screen.width and get a notification when the application moves to a different sized monitor window.

    ApplicationWindow {
    
        property int displaySize: Screen.height
    
        onDisplaySizeChanged: {
            console.log("Display Height:", displaySize)
        }
    
    }
    

    Of course, this could have problems if screens of equivalent pixel resolution exist, or a very small but high DPI screen is used, or if one screen has a menu bar much larger then the other, etc.

    The actual ideal end goal is to pass the underlying QScreen::availableGeometry() property into my QML through an existing c++ linkage (in order to take into account status bars and similar - not just physical pixel count).

    Questions:

    • What signal or variable is emmited when the application has moved screens? (either in qml or the c++ underneath)
    • What is the underlying variable the qml Screen item is receiving signals on when it moves? (spent time digging into the QML code to try and find this, but was unsuccessful. Also attempted to get notificatons on availableGeometry() in QScreen, but that seems not to fire when the QML application moves)
    • Any better suggestions for handling moving application to different screens, while taking into account menu bars and similar?

    Thank you.

    J.HilkJ 1 Reply Last reply
    0
    • A Offline
      A Offline
      antiocles
      wrote on last edited by antiocles
      #7

      There it is! Thank you! I knew there had to be something simple here I was overlooking...

      ApplicationWindow {
      
          onScreenChanged: {
              console.log("Screen Change!")
          }
      
      }
      

      To find this, you have to dig into the inherited members of ApplicationWindow. In Qt 5.9> "screen" was introduced and you now get a signal on screen change. https://doc.qt.io/qt-5/qml-qtquick-window-window.html#screen-prop

      In my case, the application does not allow resizing manually, so only need to react to this. Else you might want to also react to height/width display changes as well.

      1 Reply Last reply
      0
      • A antiocles

        Hello,

        I am implementing a multi screen application on desktop. Some screens may be restricted vertically, so I plan to adjust the UI as needed when the application is either manually moved by the user to a different screen, or I programmatically put that screen onto the smaller window.

        I can bind to the Screen.height variable or Screen.width and get a notification when the application moves to a different sized monitor window.

        ApplicationWindow {
        
            property int displaySize: Screen.height
        
            onDisplaySizeChanged: {
                console.log("Display Height:", displaySize)
            }
        
        }
        

        Of course, this could have problems if screens of equivalent pixel resolution exist, or a very small but high DPI screen is used, or if one screen has a menu bar much larger then the other, etc.

        The actual ideal end goal is to pass the underlying QScreen::availableGeometry() property into my QML through an existing c++ linkage (in order to take into account status bars and similar - not just physical pixel count).

        Questions:

        • What signal or variable is emmited when the application has moved screens? (either in qml or the c++ underneath)
        • What is the underlying variable the qml Screen item is receiving signals on when it moves? (spent time digging into the QML code to try and find this, but was unsuccessful. Also attempted to get notificatons on availableGeometry() in QScreen, but that seems not to fire when the QML application moves)
        • Any better suggestions for handling moving application to different screens, while taking into account menu bars and similar?

        Thank you.

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

        hi @antiocles and welcome

        I don't think there's a ready to use signal that you can connect to.

        But you should be able to do what you want to any way.

        I would suggest using a Eventfilter on your top most parent window.
        You'll have to filter for QEvent::NonClientAreaMouseButtonPress and QEvent::NonClientAreaMouseButtonRelease
        Those should only be triggered when the mouse was pressed on an area that can eb used to move the window around.

        But I don't know if this will also work for moving the window via keyboard shortcuts. For example WindowsKey+(any)arrowKey

        You can read more on it in this stack overflow thread:
        https://stackoverflow.com/a/55928964


        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          antiocles
          wrote on last edited by
          #3

          Hmm... that is a method I had not thought about yet and an interesting possibility that probably catches most potential cases.

          It seems there should be some sort of signal or event somewhere down the stack layers because the screen object is definitely reporting changes when you drag the application back and forth across screens.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            antiocles
            wrote on last edited by antiocles
            #4

            I would like to try and dig into the underlying code around what is happening with the qml screen object to trace backwards to determine how it is detecting being moved and updating its geometry. I am quite familiar with the c++ side and organization of qt code having patched things before, but qml is new to me and I do not understand the source tree organization.

            • Is there a guide or document explaining the source tree organization to help understand where to begin looking to find the underlying implementation of the qml side of the house?
            1 Reply Last reply
            0
            • V Offline
              V Offline
              vladstelmahovsky
              wrote on last edited by
              #5

              I suspect that there is needed some c++ catching processWindowScreenChangedEvent from QGuiApplicationPrivate

              1 Reply Last reply
              0
              • GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #6

                You can react to a screen change in qml with onScreenChanged: ...

                1 Reply Last reply
                3
                • A Offline
                  A Offline
                  antiocles
                  wrote on last edited by antiocles
                  #7

                  There it is! Thank you! I knew there had to be something simple here I was overlooking...

                  ApplicationWindow {
                  
                      onScreenChanged: {
                          console.log("Screen Change!")
                      }
                  
                  }
                  

                  To find this, you have to dig into the inherited members of ApplicationWindow. In Qt 5.9> "screen" was introduced and you now get a signal on screen change. https://doc.qt.io/qt-5/qml-qtquick-window-window.html#screen-prop

                  In my case, the application does not allow resizing manually, so only need to react to this. Else you might want to also react to height/width display changes as well.

                  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