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. extending functionality of third-party module
Forum Updated to NodeBB v4.3 + New Features

extending functionality of third-party module

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 517 Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    Hi all -

    I'm using this third-party module and need to add some functionality to it. Here's a snippet of the file I need to extend:

    Item {
        id: control
        Item {
            id: handleItem
            MouseArea {
                id: trackMouse
                onReleased: sp.value = control.value // this is the line I'm adding.
    

    I'd prefer not to modify the module if I can avoid it, but I don't see a way around it. Is there a way to "inject" the functionality of that added line without modifying the source?

    Thanks...

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      I would modify the control like this:

      Item {
          id: control
        
          signal trackMouseRelease()
      
          Item {
              id: handleItem
              MouseArea {
                  id: trackMouse
                  onReleased: trackMouseRelease()
      
      

      Then in the place you use CircularSlider:

      CircularSlider {
        id: circSlider
        onTrackMouseRelease: {
          sp.value = circSlider.value
        }
      }
      

      This way your change is generic and the object is reusable.

      C++ is a perfectly valid school of magic.

      mzimmersM 1 Reply Last reply
      0
      • fcarneyF fcarney

        I would modify the control like this:

        Item {
            id: control
          
            signal trackMouseRelease()
        
            Item {
                id: handleItem
                MouseArea {
                    id: trackMouse
                    onReleased: trackMouseRelease()
        
        

        Then in the place you use CircularSlider:

        CircularSlider {
          id: circSlider
          onTrackMouseRelease: {
            sp.value = circSlider.value
          }
        }
        

        This way your change is generic and the object is reusable.

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @fcarney your idea is great, but it's still modifying the third-party QML, which is what I'm trying to avoid. (I realize that in this instance, it's no big deal, but I'm trying to find a solution in case I eventually utilize a much larger, more elaborate third-party product.) Is there some QML equivalent to C++ subclassing where I could add or override member behavior?

        Thanks...

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          There is nothing magic you can do here if a QML object doesn't expose what you need. The best you can do is add aliases to expose objects you need access to and submit a patch to the repository. If they agree on the changes then you helped make their code more flexible.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          1
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            Why don't you just go off of value changed? Aren't you just needing the value when it changes? Every property in QML has a changed event signal that is created:

            CircularSlider {
              id: circSlider
              onValueChanged: {
                sp.value = circSlider.value
              }
            }
            

            value -> onValueChanged for the signal

            C++ is a perfectly valid school of magic.

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

              there's a pressed property for the above CircularSlider, no need to modify it.
              You can do

              CircularSlider {
                  onPressedChanged: {
                      if (!pressed)
                          sp.value = control.value;
                  }
              }
              
              mzimmersM 1 Reply Last reply
              2
              • GrecKoG GrecKo

                there's a pressed property for the above CircularSlider, no need to modify it.
                You can do

                CircularSlider {
                    onPressedChanged: {
                        if (!pressed)
                            sp.value = control.value;
                    }
                }
                
                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                @GrecKo @fcarney thank you both -- this is exactly what I was looking for. But, for some reason, fcarney's solution seems to "miss" most (not all) of the changes, at least as reported by the WRITE property of my C++ object. @GrecKo 's solution catches all of the changes. Not sure why this is (not) happening with @fcarney's solution...

                1 Reply Last reply
                1

                • Login

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