2017-05-27 31 views
0

我想在我的C++/qt/qml應用程序中添加啓動畫面。我添加以下代碼:使用qml + QQuickView作爲啓動屏幕不工作

​​

}

而且Splash.qml文件:

import QtQuick 2.0 
import QtQuick.Controls 2.1 

Item { 
    visible: true 
    width: 640 
    height: 480 
    BusyIndicator { 
     anchors.centerIn: parent 
     width: 100 
     height: 100 
     running: true 
     Component.onCompleted: { 
      console.log("splash screen... " + x + " " + y + " " + width + "x" + height) 
      visible=true 
     } 
    } 
} 

當應用程序被啓動,該消息:「QML:閃屏... 270 190 100x100「,但QQuickWindow只是白色。 main.qml的主窗口可以正常工作。我試圖在Splash.qml中加載一個圖像,但同樣的問題。而且,我不能使它成爲使用QQuickView :: setWindowFlags的無框窗口。我正在使用win7 64位操作系統。

回答

0

你可以做到這一點很容易在QML:

import QtQuick 2.7 
import QtQuick.Controls 2.0 
import QtQuick.Window 2.0 

Window { 
    id: mainWindow 
    width: 600 
    height: 400 
    visible: false 
    x: Screen.width/2 - width/2; 
    y: Screen.height/2 - height/2; 

    Window { 
     id: splashWindow 
     width: 300 
     height: 200 
     visible: true 
     x: Screen.width/2 - width/2; 
     y: Screen.height/2 - height/2; 
     flags: Qt.SplashScreen; 
     Rectangle { 
      anchors.fill: parent 
      color: "green"; 
     } 

     ProgressBar { 
      id: progressBar 
      anchors.centerIn: parent 
      anchors.margins: 20 
      value: 0.01 
     } 

     Timer { 
      id: timer 
      interval: 50 
      repeat: true 
      running: true 
      onTriggered: { 
       progressBar.value += 0.01 
       if(progressBar.value >= 1.0) { 
        timer.stop(); 
        mainWindow.visible = true; 
        splashWindow.destroy(); 
       } 
      } 
     } 
    } 
} 
相關問題