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. Cant refresh QML item only after using it.
Forum Updated to NodeBB v4.3 + New Features

Cant refresh QML item only after using it.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 333 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.
  • B Offline
    B Offline
    BD9a
    wrote on last edited by
    #1

    Hey. I have an app where user can bind keyboard buttons. When loading from config file everything works fine (even after modifying button in c++ and emitting changed signal / changing it's Text property [which is used in "Binded: .." from other element) - text in the rectangle (KeyBind qml item) is updated from for example"Binded: X" to "Binded: Y". The problem started here: when I actually use this custom qml item (KeyBind) I cant change it's text in other way without restarting an app - from cpp / from other element in qml.

    Video of the problem: (as You can see only those custom buttons are problematic)
    https://www.youtube.com/watch?v=VvmlI2IRjPk

    Code of this custom KeyBind qml element:
    https://pastebin.com/kPc7gHEx

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

      This is because you are overwriting your binding in KeyBind.

      I guess you are using it like so:

      KeyBind {
          keyName: currentProfile.keyName
      }
      

      When you change the profile or the keyName of the profile the binding gets updated like you expect but when you want to bind a new key and do Keys.onPressed: { /* ... */ root.keyName = "ALT" }, you are losing the original binding.

      What you should do is add change your activated signal to indicate which key got entered: signal activated(string keyName) and call that in Keys.onPressed : root.activated("ALT").

      Then when using KeyBind you can do that:

      KeyBind {
          keyName: currentProfile.keyName
          onActivated: keyName => currentProfile.keyName = keyName
      }
      
      1 Reply Last reply
      1
      • B Offline
        B Offline
        BD9a
        wrote on last edited by
        #3

        Didnt know about breaking bindings yet and I feel like I dont understand the code onActivated well.
        What does => means / how it's named?
        Currently the custom item is defined like this:

                LeftBind {
                    id: enabler
                    x: 291
                    y: 15
                    keyName: keyTranslator.getKey(Config.enabler) //Config.enabler is vkey (int), this function converts it to readable string (for example from c++ vkey 0x10 to "ALT")
                    onAccepted: {
                        var a = keyTranslator.getCode(keyName); // from string to vkey
                        if(a === 404){
                            askForKey()
                        } else {
                            Config.set_enablerBtn(a)
                        }
                    }
                }
        
        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