Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why RangeSlider is available in QtQuick and not as standard Widget

Tags:

c++

qt

I need something like a range slider (a slider that has two handles for setting min/max values).

I noticed that there is a RangeSlider in QtQuick and QML (Whatever that is), but there is not a 'standard widget' such as QRangeSlider.

Why is this?

Can I use that RangeSlider from QtQuick without writing QML code?

like image 550
manatttta Avatar asked Jan 31 '26 10:01

manatttta


2 Answers

In my project I successfully used the Common TK range slider.

It looks like this:

enter image description here

Practical class ready to go here: CPP and header

like image 116
Massimo Callegari Avatar answered Feb 03 '26 01:02

Massimo Callegari


Since RangeSlider is a QML type you need QML context to use it in. QQuickWidget is just a QWidget that specializes in loading and displaying QML contents. The fact that it's just another subclass of it enables you to integrate it into a QWiget of your choice. See here for an example of how to integrate these two (the example uses QMainWindow but you can adapt it to your needs.

My guess for this missing UI component in a standard QWidget would be that:

  • it can easily be created by the developer by tweaking the QSlider (example)
  • the QWidget-related stuff in terms of new features from the Qt Company is basically dead since they go full speed towards QML. I don't like it but that's how things are
  • range sliders aren't that popular. You can easily replace a slider (that needs to support a range) with two sliders (one for lower and one for upper limit), two QSpinBoxes etc.

Better solution would be to dump the QML stuff for this and implement your own version in C++.

like image 24
rbaleksandar Avatar answered Feb 03 '26 00:02

rbaleksandar



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!