码迷,mamicode.com
首页 > 其他好文 > 详细

如何在QML应用中实现一个Splash画面

时间:2015-05-25 09:58:11      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

在QML应用中,我们经常要用到一个SplashScreen的画面来渲染我们的应用。那么我们怎么在自己的应用中做一个Splash Screen呢?


首先我们来设计一个自己的SplashScreen的QML模块:


SplashScreen.qml


import QtQuick 2.0

Item {
    id: splash
    anchors.fill: parent

    property int timeoutInterval: 2000
    signal timeout

    Image {
        id: splashImage
        anchors.fill: parent
        source: "images/splash.jpg"
    }

    Timer {
        interval: timeoutInterval; running: true; repeat: false
        onTriggered: {
            visible = false
            splash.timeout()
        }
    }
}


这里的设计非常简单。我们使用了一个图片来显示自己的画面。同时,我们使用了一个Timer。当Timer timeout时,我们就发生一个信号。这个信号,可以被外界所使用。这也是好一个好的方法让我们的模块和别的模块之间有一个好的隔离。我们可以在其它的模块中利用这个timout信号来实现我们想要做的事情。

Main.qml


在这个模块中,我们直接使用SplashScreen.qml:

import QtQuick 2.0
import Ubuntu.Components 1.1

/*!
    \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: "splashscreen.liu-xiao-guo"

    /*
     This property 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(60)
    height: units.gu(85)

    Page {
        title: i18n.tr("Splashscreen")

        MainWindow {
            id: mainwindow
            anchors.fill: parent
            visible: false
        }

        SplashScreen {
            onTimeout: {
                console.log("it times out!");
                mainwindow.visible = true;
            }
        }
    }
}

在SplashScreen中,我们捕获timeout信号,并使得MainWindow显现。当然我们也可以实现自己的一些特效。这样我们就可以实现我们想要的功能。

技术分享    技术分享

整个项目的源码在:git clone https://gitcafe.com/ubuntu/splashscreen.git

如何在QML应用中实现一个Splash画面

标签:

原文地址:http://blog.csdn.net/ubuntutouch/article/details/45965665

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!