Tumbler - how to restrict movement?



  • Hi all,

    I have Tumbler with one column and a model of minutes 0-100
    I would like to add restriction so the wheel could change values sort of like SpinBox from 0 to 100 but not flip around.
    In other words when Tumbler displays 0 - disable "down" wheel movement, so user cannot select 100
    when Tumbler displays 100 - disable "up" wheel movement so user cannot select 0
    Don't know how to do it. Possible?

    Best Regards
    Marek



  • Hi @Marek

    This is how you can detect that you have to block mouvement :

                 property int lastIndex
    
                onCurrentIndexChanged: {
                      lastIndex = currentIndex-1
                     
                       if(lastIndex<0||lastIndex>=(model-2)){
                                console.log("need lock")
                               }
                    }
    

    But i don't know how to dynamicaly lock mouvement when user slides and reachs extrem values.

    One solution could be to block mouse interaction (set 'enabled' property to false on the tumbler) and add 2 buttons to select values (+1 / -1), then you can hide button when needed... but this is not exactly what you want i imagine.
    BR
    LA





  • I fixated on Tumbler when I was picking up Qt && QML. If you want just the look and feel of default Tumbler (but not the operation) - you could just style a ListView with the same default gradient Tumbler uses.

    Does nearly the same (except Tumbler always has a currentIndex) with much less.
    https://doc.qt.io/qt-5/qml-qtquick-controls2-tumbler.html

    The (tumbler) API is similar to that of views like ListView and PathView; 
    a model and delegate can be set, and the count and currentItem properties provide read-only access to information about the view.
    
    Unlike views like PathView and ListView, however, there is always a current item
     (when the model is not empty). This means that when count is equal to 0, currentIndex will be -1.
    In all other cases, it will be greater than or equal to 0.
    


  • Hi

    Thanks all for hints.
    I know ListView could do the same as Tumbler but I thought Tumbler will require less code to work ;)
    I went for a Tumbler with "wrap" property and customized it to my needs.

    Don't get me wrong, I like Qt, I do it for a living, but current state of QML objects is a mess.
    There are 2 or 3 types of Tumbler one of them has "wrap" property another has not, they have different look, different property names (currentIndex, setCurrentIndexAt).
    Will this ever be unified like with Qt Widgets?

    Best Regards
    Marek


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.