2017-05-27 11 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ビットOSで作業しています。

答えて

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(); 
       } 
      } 
     } 
    } 
} 
関連する問題