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. Open/show and close/hide popup by QML code
Forum Updated to NodeBB v4.3 + New Features

Open/show and close/hide popup by QML code

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • M Offline
    M Offline
    m3g1dd
    wrote on 21 Oct 2020, 12:05 last edited by m3g1dd
    #1

    There is a Q_PROPERTY in my registered C++ class:

    // C++ Class
    Q_PROPERTY(bool inProgress READ inProgress WRITE setInProgress NOTIFY inProgressChanged)
    

    ... based on which I intend to show a QML popup:

    Popup {
        id: popup
        visible: cppClass.inProgress // Bind visibility to C++ Q_PROPERTY
    }
    

    But the pop doesn't show up. If change visible to true the popup is always shown of course.

    Tried so far

    Tried to use signal/slot connections to open/show the popup, but doesn't work:

    Popup {
        id: popup
        visible: false
    
        Connections {
            target: cppClass
            onInProgressChanged: {
                if (cppClass.inProgress) {
                    console.log("open ...")                   // This text is logged correctly
                    popup.visible = Qt.binding(function(){return true}) // popup is NOT shown
                    popup.open()                                        // popup is NOT opened
                } else {
                    console.log("close ...")
                    popup.visible = Qt.binding(function(){return false})
                    popup.close()
                }
            }
        }
    }
    

    What am I missing?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 21 Oct 2020, 12:09 last edited by
      #2
      Popup {
          id: popup
          visible: cppClass.onProgress // Bind visibility to C++ Q_PROPERTY
      }
      

      You have a typo here (should be inProgress, not onProgress).

      The code seems correct, it should work. Some suggestions:

      • make sure you don't have that typo in actual code :-)
      • perhaps inProgress is changed when some very heavy, CPU-blocking operation is ongoing? Then QML engine might not have time to show the GUI changes. Try setting inProgress first, then starting the CPU-heavy operation after some time, or in a different thread
      • maybe you are setting inProgress to false immediately after you set it to true (the operation completes very fast)?
      • make sure the inProgressChanged signal is being emitted

      (Z(:^

      M 2 Replies Last reply 21 Oct 2020, 12:14
      2
      • S sierdzio
        21 Oct 2020, 12:09
        Popup {
            id: popup
            visible: cppClass.onProgress // Bind visibility to C++ Q_PROPERTY
        }
        

        You have a typo here (should be inProgress, not onProgress).

        The code seems correct, it should work. Some suggestions:

        • make sure you don't have that typo in actual code :-)
        • perhaps inProgress is changed when some very heavy, CPU-blocking operation is ongoing? Then QML engine might not have time to show the GUI changes. Try setting inProgress first, then starting the CPU-heavy operation after some time, or in a different thread
        • maybe you are setting inProgress to false immediately after you set it to true (the operation completes very fast)?
        • make sure the inProgressChanged signal is being emitted
        M Offline
        M Offline
        m3g1dd
        wrote on 21 Oct 2020, 12:14 last edited by
        #3

        @sierdzio Thanks! There is no typo in the actual code. I'm going to check the other suggested items.

        1 Reply Last reply
        1
        • S sierdzio
          21 Oct 2020, 12:09
          Popup {
              id: popup
              visible: cppClass.onProgress // Bind visibility to C++ Q_PROPERTY
          }
          

          You have a typo here (should be inProgress, not onProgress).

          The code seems correct, it should work. Some suggestions:

          • make sure you don't have that typo in actual code :-)
          • perhaps inProgress is changed when some very heavy, CPU-blocking operation is ongoing? Then QML engine might not have time to show the GUI changes. Try setting inProgress first, then starting the CPU-heavy operation after some time, or in a different thread
          • maybe you are setting inProgress to false immediately after you set it to true (the operation completes very fast)?
          • make sure the inProgressChanged signal is being emitted
          M Offline
          M Offline
          m3g1dd
          wrote on 21 Oct 2020, 13:10 last edited by
          #4

          @sierdzio The code worked by triggering C++ signals further away from CPU-blocking operation.

          1 Reply Last reply
          0

          1/4

          21 Oct 2020, 12:05

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved