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. How to close a popup window using closePolicy in QML

How to close a popup window using closePolicy in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 4.7k 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.
  • mamoudM Offline
    mamoudM Offline
    mamoud
    wrote on last edited by mamoud
    #1

    Hi,
    I have this popupwindow and I want to close it using closePolicy, when I press ESC on keyboard, it closes

        PopupWindow {
            id: Acurve
            width: 300
            height: 120
            title: "Test"
            opacity: 0
            visible:false
        }
    

    I tried to write closPolicy:
    but it seems that I need to define this property first as enumeration, but i dont know how?

    There is something called (Popup.CloseOnEscape) but I am not sure how to implement it

    J.HilkJ 1 Reply Last reply
    0
    • mamoudM mamoud

      Hi,
      I have this popupwindow and I want to close it using closePolicy, when I press ESC on keyboard, it closes

          PopupWindow {
              id: Acurve
              width: 300
              height: 120
              title: "Test"
              opacity: 0
              visible:false
          }
      

      I tried to write closPolicy:
      but it seems that I need to define this property first as enumeration, but i dont know how?

      There is something called (Popup.CloseOnEscape) but I am not sure how to implement it

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

      @mamoud
      what is PopupWindow is that part oif the normal QML lib ?
      I know of the Popup-item and you can very easily defined the close options

      Popup {
              id: Acurve
              width: 300
              height: 120
              title: "Test"
              opacity: 0
              visible:false
      
             closePolicy: Popup.CloseOnEscape
          }
      

      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.

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

        @mamoud
        what is PopupWindow is that part oif the normal QML lib ?
        I know of the Popup-item and you can very easily defined the close options

        Popup {
                id: Acurve
                width: 300
                height: 120
                title: "Test"
                opacity: 0
                visible:false
        
               closePolicy: Popup.CloseOnEscape
            }
        
        mamoudM Offline
        mamoudM Offline
        mamoud
        wrote on last edited by
        #3

        @J.Hilk said in How to close a popup window using closePolicy in QML:

           closePolicy: Popup.CloseOnEscape
        

        Thank you for reply, but I typically copied paste your code and got this error

        Invalid property name "closePolicy"

        J.HilkJ 1 Reply Last reply
        0
        • mamoudM mamoud

          @J.Hilk said in How to close a popup window using closePolicy in QML:

             closePolicy: Popup.CloseOnEscape
          

          Thank you for reply, but I typically copied paste your code and got this error

          Invalid property name "closePolicy"

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

          @mamoud
          like I said thats for the normal Popup -item, I don't know about PopupWindow

          example for a ppopup directly from the docu:

          import QtQuick.Window 2.2
          import QtQuick.Controls 2.1
          
          ApplicationWindow {
              id: window
              width: 400
              height: 400
              visible: true
          
              Button {
                  text: "Open"
                  onClicked: popup.open()
              }
          
              Popup {
                  id: popup
                  x: 100
                  y: 100
                  width: 200
                  height: 300
                  modal: true
                  focus: true
                  closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
              }
          }
          

          https://doc.qt.io/qt-5.11/qml-qtquick-controls2-popup.html#details


          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.

          mamoudM 2 Replies Last reply
          0
          • J.HilkJ J.Hilk

            @mamoud
            like I said thats for the normal Popup -item, I don't know about PopupWindow

            example for a ppopup directly from the docu:

            import QtQuick.Window 2.2
            import QtQuick.Controls 2.1
            
            ApplicationWindow {
                id: window
                width: 400
                height: 400
                visible: true
            
                Button {
                    text: "Open"
                    onClicked: popup.open()
                }
            
                Popup {
                    id: popup
                    x: 100
                    y: 100
                    width: 200
                    height: 300
                    modal: true
                    focus: true
                    closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
                }
            }
            

            https://doc.qt.io/qt-5.11/qml-qtquick-controls2-popup.html#details

            mamoudM Offline
            mamoudM Offline
            mamoud
            wrote on last edited by
            #5

            @J.Hilk said in How to close a popup window using closePolicy in QML:

                closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
            
                Popup {
                    id: adAcurve
                    width: 300
                    height: 120
                    title: "Test."
                    opacity: 0
                    visible:false
                    closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
            

            I tried this but get the same error

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

              @mamoud
              like I said thats for the normal Popup -item, I don't know about PopupWindow

              example for a ppopup directly from the docu:

              import QtQuick.Window 2.2
              import QtQuick.Controls 2.1
              
              ApplicationWindow {
                  id: window
                  width: 400
                  height: 400
                  visible: true
              
                  Button {
                      text: "Open"
                      onClicked: popup.open()
                  }
              
                  Popup {
                      id: popup
                      x: 100
                      y: 100
                      width: 200
                      height: 300
                      modal: true
                      focus: true
                      closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
                  }
              }
              

              https://doc.qt.io/qt-5.11/qml-qtquick-controls2-popup.html#details

              mamoudM Offline
              mamoudM Offline
              mamoud
              wrote on last edited by
              #6

              @J.Hilk

              but if you checked th Popup in your file, how is closePolicy property is defined please?
              I checked my Popup, but property closePolicy is not defined in the file

              1 Reply Last reply
              0
              • mamoudM Offline
                mamoudM Offline
                mamoud
                wrote on last edited by
                #7

                Hey any help,
                I know how to implement the popup, but in my popup file, the property closePolicy is not defined, can I know how it is defined?

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

                  Do you have exactly these import statements?

                  import QtQuick.Window 2.2
                  import QtQuick.Controls 2.1
                  

                  What is the content of your pro file?

                  You reap what you sow it

                  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