[Interest] How to set QtQuickControls Slider to an initial value without modifying the current saved?

Nuno Santos nunosantos at imaginando.pt
Fri Oct 17 10:48:03 CEST 2014


Hummm 

This Settings QML type is awesome and I didn’t knew it. I had a QSettings class exposed to QML and I was declaring all the properties I needed. This really saves a lot of work. Should I really on it for a production product? 

Regards,

Nuno

On 17 Oct 2014, at 09:43, Nurmi J-P <jpnurmi at theqtcompany.com> wrote:

>> 
>> On 16 Oct 2014, at 17:39, Nuno Santos <nunosantos at imaginando.pt> wrote:
>> 
>> Hi,
>> 
>> I’m using Slider from QtQuickControls and i’m facing a problem. I initialise the value with a value saved on settings. However, when the slider is instantiated, it is triggering onValueChanged with the default min value. The setting is being correctly saved because I don’t show the slider right away. Only when the slider is show, this is happening and I see the result of the change in settings. 
>> 
>> Slider {
>>   width: parent.width
>>   height: 10
>>   minimumValue: 60
>>   maximumValue: 180
>>   stepSize: 1
>>   updateValueWhileDragging: true
>>   value: settings.trackWidth
>>   onValueChanged: {
>>       console.log("track width value changed: " + value)
>>       settings.trackWidth = value
>>   }
>>   Component.onCompleted: {
>>       console.log("track width on completed: " + settings.trackWidth)
>>       value = settings.trackWidth
>>   }
>> }
>> 
>> Console:
>> 
>> qml: track width value changed: 60
>> qml: track width on completed: 60
>> 
>> Any ideas?
> 
> 
> Hi,
> 
> How about:
> 
> import QtQuick 2.3
> import QtQuick.Controls 1.2
> import Qt.labs.settings 1.0
> 
> ApplicationWindow {
>    width: 320
>    height: 200
>    visible: true
> 
>    Settings {
>        id: settings
>        property alias sliderValue: slider.value
>    }
> 
>    GroupBox {
>        title: slider.value
>        Slider {
>            id: slider
>            stepSize: 1
>            minimumValue: 60
>            maximumValue: 180
>            anchors.centerIn: parent
>        }
>    }
> }
> 
> http://qt-project.org/doc/qt-5/qml-qt-labs-settings-settings.html
> 
> --
> J-P Nurmi

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20141017/af33fdfc/attachment.html>


More information about the Interest mailing list