3

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

4

1 回答 1

2

你只需要创建一个新的 qml 文件

假设你将它命名为 MySlider.qml。

MySlider.qml:

import QtQuick 2.0
import QtQuick.Controls 1.0

Slider {
    // anything you want
}

现在您可以使用 MySlider 作为新组件

main.qml

...
...
MySlider {
}
...
...
于 2014-06-26T08:29:50.960 回答