From d2d0bfe830330f30913973a79c080d3cc5b00a21 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 19 Sep 2014 11:46:44 +0200 Subject: Fix disappearing slider during size/orientation change Now the slider remains at a position that is equivalent to the old position based on the previous percentage. This change is most commonly triggered during orientation changes on mobile device. That is the reason why the app was converted to a proper Qt project. This way it was possible to test this behavior on Android. Task-number: QTBUG-18423 Change-Id: If05e6a1e42249f90a821c4882021d28cf212fc52 Reviewed-by: Simon Hausmann --- .../quick/customitems/dialcontrol/dialcontrol.qml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'examples/quick/customitems/dialcontrol/dialcontrol.qml') diff --git a/examples/quick/customitems/dialcontrol/dialcontrol.qml b/examples/quick/customitems/dialcontrol/dialcontrol.qml index f545877655..0bf6d7e68c 100644 --- a/examples/quick/customitems/dialcontrol/dialcontrol.qml +++ b/examples/quick/customitems/dialcontrol/dialcontrol.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the examples of the Qt Toolkit. @@ -39,7 +39,8 @@ ****************************************************************************/ //! [imports] -import QtQuick 2.0 +import QtQuick 2.2 +import QtQuick.Window 2.1 import "content" //! [imports] @@ -53,12 +54,13 @@ Rectangle { Dial { id: dial anchors.centerIn: parent - value: slider.x * 100 / (container.width - 34) + value: slider.x * 100 / (container.width - 32) } //! [the dial in use] Rectangle { id: container + property int oldWidth: 0 anchors { bottom: parent.bottom; left: parent.left right: parent.right; leftMargin: 20; rightMargin: 20 bottomMargin: 10 @@ -73,6 +75,17 @@ Rectangle { GradientStop { position: 1.0; color: "white" } } + onWidthChanged: { + if (oldWidth === 0) { + oldWidth = width; + return + } + + var desiredPercent = slider.x * 100 / (oldWidth - 32) + slider.x = desiredPercent * (width - 32) / 100 + oldWidth = width + } + Rectangle { id: slider x: 1; y: 1; width: 30; height: 14 -- cgit v1.2.3