QML custom scrolling Text control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.15 | |
import QtQuick.Window 2.15 | |
Window { | |
width: 640 | |
height: 480 | |
visible: true | |
title: qsTr("https://dabreha.blogspot.com/") | |
property string intro: "I Am Aksh Singh,I Am An Embedded Software Developer ,Results-oriented Embedded Software Engineer with 2+ years experience in analysis, design, development, testing, and implementation of embedded software systems. Adept at designing and building applications with usability and high performance in mind" | |
Rectangle { | |
width: parent.width-100 | |
height: 50 | |
anchors.centerIn: parent | |
color: "transparent" | |
clip: true | |
TextSlider { | |
anchors.verticalCenter: parent.verticalCenter | |
width: 150 | |
anchors.centerIn: parent | |
text: intro | |
font.pixelSize: 20 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.6 | |
Text { | |
id: root | |
onXChanged: _xChanged() | |
onTextChanged: _textChanged() | |
Component.onCompleted: _init() | |
/* animation */ | |
SequentialAnimation { | |
id: leftMovement | |
PropertyAnimation { | |
target: root | |
property: "x" | |
from: 0 | |
to: (root.width - _text.width - 5) | |
duration: 50000 | |
} | |
} | |
SequentialAnimation { | |
id: rightMovement | |
PropertyAnimation { | |
target: root | |
property: "x" | |
from: (root.width - _text.width - 5) | |
to: 0 | |
duration: 50000 | |
} | |
} | |
// To get the 'width' fo 'text' | |
Text { | |
id: _text | |
visible: false | |
text: parent.text | |
font.pixelSize: parent.font.pixelSize | |
} | |
/* private function */ | |
function _xChanged() { | |
if (x == (root.width -_text.width - 5)) { | |
rightMovement.start() | |
} | |
else if (x == 0){ | |
leftMovement.start() | |
} | |
} | |
function _textChanged() { | |
if (_text.width <= root.width) { | |
rightMovement.stop() | |
leftMovement.stop() | |
} | |
else { | |
anchors.centerIn = null | |
leftMovement.start() | |
} | |
} | |
function _init() { | |
if (_text.width > root.width) { | |
anchors.centerIn = null | |
leftMovement.start() | |
} | |
} | |
} |