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. Force active focus on top QML Window
Forum Updated to NodeBB v4.3 + New Features

Force active focus on top QML Window

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

    Hi,

    I swear I've done this before on a previous project, but I can't for the life of me figure out how to do this! I've got an ApplicationWindow, with a Loader which opens an external QML Window. The new Window uses the WindowStaysOnTopHint flag, so it remains the top window in the application.

    However, I'm still able to interact with the ApplicationWindow beneath (hover events, clicking, etc.), including losing focus to the ApplicationWindow beneath when clicking the mouse outside of the top Window. Is there a way to 'lock' the focus on the top Window, such that any clicks outside the Window are ignored?

    Here's a high-level representation of my code:

    main.qml:

    ApplicationWindow {
        id: mainWindow
        visible: true
        title: "Main Window"
    
        //RowLayouts, Columns, etc.
    
        Loader {
            id: loader
        }
    
        //Elsewhere in the ApplicationWindow, a MouseArea event sets the loader source to other.qml
    }
    

    other.qml:

    Window {
        id: otherWindow
        visible: true
        title: "Other Window"
        flags: Qt.WindowStaysOnTopHint
        minimumWidth: 400
        minimumHeight: 400
        color: "red"
    }
    

    As you can see, it's a fairly simple use case; I just need to ensure that once the 'Other Window' has been loaded, all focus/mouse activity outside of this window (i.e. clicking on the Main Window below) is ignored/prevented.

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      It sounds like you're describing an application-modal window.

      Window {
          Window.modality: Qt.ApplicationModal
      }
      

      Asking a question about code? http://eel.is/iso-c++/testcase/

      J 1 Reply Last reply
      2
      • jeremy_kJ jeremy_k

        It sounds like you're describing an application-modal window.

        Window {
            Window.modality: Qt.ApplicationModal
        }
        
        J Offline
        J Offline
        jars121
        wrote on last edited by jars121
        #3

        @jeremy_k That's it! Thank you very much, I knew it was something simple I'd forgotten.

        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