How to vibrate in Ubuntu QML applications (Vibration)

Source: Internet
Author: User
Tags i18n git clone

For some QML applications, vibration is a very important function. Especially for the game. So how do we vibrate in the QML application?


We officially have an API Hapticseffect, the function of this API is to let our application to vibrate. Using this API is easy:


Import QtQuick 2.0import ubuntu.components 1.1import qtfeedback 5.0/*! \brief MainView with a Label and Button Elements.*/mainview {//ObjectName for functional testing purposes (autopilot- QT5) ObjectName: "MainView"//note!     ApplicationName needs to match the "name" field of the click Manifest ApplicationName: "Vibration.liu-xiao-guo"/* The enables the application to change orientation when the device is rotated.    The default is False.    *///automaticorientation:true//Removes the old toolbar and enables new features of the new header.        Usedeprecatedtoolbar:false width:units.gu (height:units.gu) page {title:i18n.tr ("vibration") Hapticseffect {id:rumbleeffect attackintensity:0.0 attacktime:250 in            tensity:1.0 duration:100 fadetime:250 fadeintensity:0.0} Column { Spacing:units.gu (1) anchors {margins:units.gu (2) Fill:parent} Button {OB                Jectname: "button" Width:parent.width text:i18n.tr ("Vibrate me!")  OnClicked: {Rumbleeffect.start (); Plays a rumble Effect}}}}

Here we import the libraries we need:

Import Qtfeedback 5.0

Then, instantiate our Hapticseffect:

  Hapticseffect {            id:rumbleeffect            attackintensity:0.0            attacktime:250            intensity:1.0            Duration:            fadetime:250            fadeintensity:0.0        }

When we press our button, we start shaking. Of course this must be on the phone to be able to test.


The source code for the entire project is: Git clone https://gitcafe.com/ubuntu/vibration.git

How to vibrate in Ubuntu QML applications (Vibration)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.