Sunday, 15 January 2012

qt - How to set initial value of a custom slider in qml? -


I am using QT 5.4.1 I have created a custom slider element to be used in such other qml components :

slider. Qml
  Import QTclick 2.4 Import QtQuick.Controls 1.3 Import QtQuick.Controls Styles 1.3 Item {ID: Root Width: 150 Height: 30 Property Ent Val: Slider. Value property XMTVL: slider.maximavalue property int minim: slider.mahanmaluacu property int phase: slider.step size slider {id: slider anchor. Margin: 20 steps Size: Maximum max value: maxVal minimumValue: minVal Style: customStyle // onValueChanged: Print ("from slider .qml", value)} component {id: custom style slider style {handle: rectangle} {width: 20 height : 12 Antialiasing: Correct Color: Qt.lighter ("# 468bb7", 1.2)} Drain: Item {Instinct Hight: Root. Height Intuit Wideth: Root.width Rectangle {Height: 8 Width: Parent.width Anchor. Dissection Center: Parent. Specific Center Color: "# 847878" Opacity: 0.8 Rectangle {Antialising: True Radius: 1 Color: "# 1AD" Height: Original. Width: Parent.width * control.value / control.maximumValue}}}}}  

and in another file test.qml I use this slider I am like

test.qml
  import QtQuick 2.3 rectangle {ID: test width: 640; Height: 480 slider {ID: slider width: 300 height: 30 anchors. At the center: Parents Maxwell: 1000 minutes Volume: 0 Steps: 50 Val: 500 / When commented, On slip is triggered on the On-Changed Walk Change: Print (Wal)}}  < / Pre> 

I am inserted into test.qml , when using the property val , we want to set the slider in the initial value. If I set the value, the on well marked is not triggered when slideing the slider Ta. But when I comment out of that line ( val: 500 ), onValChanged gets started when the slider is slipped, but the starting value of the slider starts with 0 That's what I do not want to do. I do not know what I'm doing wrong!

property val your slider as defined in a component The specific value is override binding after the binding is lost, any updates to the slider are not distributed on val as a result of which you feel. On the other hand, if you do not set the property, the binding is maintained, as if the value of the slider changes according to val , triggers the signal.

This is not the way to go in this case, because you are adding a set of properties which only exposes the inner properties of the slider . Simply use properties:

The property is the nickname property that holds the context of another property . Contrary to a simple property definition, which allocates a new, unique storage space for the property, an asset surname combines newly declared property (called aliasing property) current assets Direct reference of (Allied property).

Re-type Slider.qml inside your properties:

  property nickname Val: slider.value property alias maxVal : Slider. Maxim Value Property Surname minVal: Slider. Minimum Price Attribute Alias: Slider. Stats size  

val slider.value and so on Setting it to 500 directly affects the slider without any compulsion.

On a sidenote, you also type for example

  property alias maximum value: slider. Highlight  

i.e. to maintain consistency in naming APIs with your very similar name .


No comments:

Post a Comment