extending functionality of third-party module
-
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...
-
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.
-
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.
@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...
-
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.
-
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
-
there's a
pressed
property for the aboveCircularSlider
, no need to modify it.
You can doCircularSlider { onPressedChanged: { if (!pressed) sp.value = control.value; } }
-
there's a
pressed
property for the aboveCircularSlider
, no need to modify it.
You can doCircularSlider { onPressedChanged: { if (!pressed) sp.value = control.value; } }
@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...