Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Functionality / behavior to a QML Slider.

Is it possible to create a subclass of a QML element?

I was trying to create a custom QML slider (as opposed to the one available in QtQuick.Controls). So I wanted to look and feel to remain the same while the range itself to behave logarithmically (not arithmatically).

I know it is possible for me to define a custom slider in c++, register it with QML and then use it in QML. But I wanted to see if i could reuse the existing QML slider by creating a subclass so that I can change only what I want to change and everything else behaves the same as the QML Slider.

So. Is it possible to create a custom subclass of a QML element.

Thank you

like image 884
OneRandomCoder Avatar asked Dec 30 '25 12:12

OneRandomCoder


1 Answers

You just have to create a new qml file

say you name it MySlider.qml.

MySlider.qml :

import QtQuick 2.0
import QtQuick.Controls 1.0

Slider {
    // anything you want
}

Now you can use MySlider as a new component

main.qml

...
...
MySlider {
}
...
...
like image 140
BlueMagma Avatar answered Jan 01 '26 02:01

BlueMagma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!