Bi-direction Text Moving Using Qt Qml | Text scrolling effect Qt Qml

Info Thread
By -
22 minute read
0

 QML Editor - IntelliJ IDEs Plugin | Marketplace

QML custom scrolling Text control

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
}
}
}
view raw main.qml hosted with ❤ by GitHub
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()
}
}
}
view raw TextSlider.qml hosted with ❤ by GitHub
Tags:

Post a Comment

0Comments

Post a Comment (0)