Qt Quick Play GIF animation

Source: Internet
Author: User

Qt Quick provides a class animatedimage that can play Gif animations, using simple, here is an example.

Here is the Gif image used:


Animatedimage

The Animatedimage provides five properties:

    • Currentframe, indicating the number of frames currently being played
    • Framecount, indicating the total number of frames of the picture
    • Paused, indicating whether to pause, set it to pause or resume playback
    • Playing that indicates whether the animation is playing, by default true, meaning that the Animatedimage object starts playing immediately after it is created
    • Source, type URL, specifies the picture address to play, which enables local files, resources in the QRC, network files

playgif Example

The playgif example can play, pause GIF, display the current frame and total frames, and an exit button, very simple.

Create a new Qt Quick App project, add shapes.gif to the Qrc file, and we'll access it through "qrc:/shapes.gif" in the QML code.

MAIN.QML content is as follows:

Import QtQuick 2.3import Qtquick.window 2.2import qtquick.controls 1.2Window {visible:true;    Width:animated.width;    Height:animated.height + 40;        animatedimage {id:animated;        Source: "Qrc:/shapes.gif";        Oncurrentframechanged: {info.text = "%1/%2". Arg (Animated.currentframe). Arg (Animated.framecount);        }} row{Spacing:4;        Anchors.horizontalCenter:parent.horizontalCenter;        Anchors.bottom:parent.bottom;        Anchors.bottommargin:4;            Text {id:info;            width:60;            height:24;            Color: "Red";            VerticalAlignment:Text.AlignVCenter;        HorizontalAlignment:Text.AlignRight;            } Button {width:60;            height:24; Text: (animated.paused = = True)?            "Play": "Pause";        onClicked:animated.paused =!animated.paused;            } Button {width:60;            height:24; Text: "QuiT ";        OnClicked:Qt.quit (); }    }}

Main.cpp is the code generated by the New Project Wizard, which does not have to be listed.

The following is the effect that is playing while the program is running, and the Play/pause button displays Pause:


The following is the effect of pausing:



OK, the example is Jiangzi.


Look back at my QT Quick Series articles:

    • About Qt Quick
    • QML Language Basics
    • Qt Quick's Hello World text
    • Qt Quick Simple Tutorial
    • The signal and slot of Qt Quick event processing
    • Qt Quick Event Processing mouse, keyboard, timer
    • Pinch scaling and rotation of Qt Quick event processing
    • Qt Quick component and Object dynamic creation
    • Introduction to Qt Quick layout
    • Qt Quick's QML and C + + mixed programming
    • Qt Quick Image Processing example of beauty 美图秀秀 (with source download)
    • Qt Quick's Pathview detailed
    • Qt Quick Example Digging avatar
    • A file viewer for the Qt quick Synthesis instance
    • QT Quick Debug Display code line number
    • Qt Quick implementation of graffiti program


Qt Quick Play GIF animation

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.