Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
Slider and Progress Bar in Qt and Windows Phone
This code example shows how to create a slider and progress bar, and link their values together, using Qt and Windows Phone.
This article shows how to create a slider and progress bar in Qt (QML) and Windows Phone. When the slider value is changed we will change the value of the progress bar accordingly. A screenshot of the UI on both platforms is shown below:
Note that in both cases we update the text and progress bar in an event handler when the slider changes. We could also have used data binding to link the slider and progress bar values.
Qt Project (MainPage.qml)
progressValue = value;
targetProgressBar.value = value;
When we move the Slider it emits the valueChanged signal, which is handled in onValueChanged(). In the handler we update the value of the Progress Bar, which we reference by its id. In the handler we also update the property progressValue with the slider value - while not shown here, this is a property of the parent object which is used to populate a text field with the slider value.
WP7 Project (MainPage.xaml)
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Slider Minimum ="0" Maximum="100" Height="84" HorizontalAlignment="Left" Margin="12,363,0,0" Name="slider1" VerticalAlignment="Top" ValueChanged="slider1_ValueChanged" Width="434" />
<TextBlock Height="71" HorizontalAlignment="Left" Margin="12,148,0,0" Name="textBlock1" Text="Progress 0%" VerticalAlignment="Top" Width="434" FontSize="38" TextAlignment="Center" />
<ProgressBar Minimum="0" Maximum="100" Value="0" Height="33" HorizontalAlignment="Left" Margin="12,225,0,0" Name="progressBar1" VerticalAlignment="Top" Width="434" />
When user moves the Slider the event handler slider1_ValueChanged() is called. This is where we update the progress bar and text block.
private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
string msg = e.NewValue.ToString("0");
this.textBlock1.Text ="Progress "+ msg+"%";
progressBar1.Value = e.NewValue;
This article is being created for beginners to show how the UI elements can relate with each other in both the platforms.