Qml粒子&帆布

时间:2016-12-04 08:13:53

标签: canvas qml particles

我让这种情况变得尽可能简单:我正在创建Item / Window / Rectangle /包含自定义粒子系统的任何东西。

Window {
    MyParticles {
        anchors.fill: parent
    }
}

我还有一个在其内部使用画布的项目:

  Item {
        Canvas {
            anchors.fill: parent
            onPaint: {
                var ctx = canvas.getContext('2d') //without that line everything works fine
                //nothing further
            } 
        }
}

如果我将它们放在一起(在一个父母内部,在有一个共同父母的不同父母内),粒子系统将不会出现,直到我将玩窗口(在5-7秒内调整大小),其中包含他们的共同父母。如果我不碰这个,Particles会工作(console.log),但我根本看不到它们。好像当我调整窗口大小或最小化&显示回来,我打电话给"重拍"在窗口和它的孩子。只有在我使用Canvas项目时才会发生这种情况。所有其他项目适用于那些粒子。 Qt5.7,mingw32,Windows 7.顺便说一句,相同的代码就像Mac OS Sierra下的魅力一样。 如何解决此问题?

更新

正如所建议的:专业档案:

TEMPLATE = app
QT += qml quick widgets
CONFIG += c++11

SOURCES +=  main.cpp
RESOURCES += qml.qrc

qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.cpp:

#include <QApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

main.qml:

import QtQuick 2.7
import QtQuick.Window 2.2

Window {
    id: root
    visible: true
    width: 300
    height: 300
    color: "black"

    TabBorder {
        id: border
        x:5
        y:5
        width: 200
        height: 75
        //Component.onCompleted: border.prepare()
    }
}

TabBorder.qml:

import QtQuick 2.7

Item {
    id: root
    height: parent.height
    width: parent.width

    Particles {
        id: particles
        anchors.fill: parent
        visible: true
        x: 5
        y: 5
        z:2
    }

    /*function prepare() {
        timer.running = true
    }

    Timer {
        id: timer
        running: false
        interval: 300
        onTriggered: {
            canvas.prepeared = true
        }
    }*/

    Canvas {
        id: canvas
        width: parent.width
        height: root.height
        /*property bool prepeared: false
        onPrepearedChanged: requestPaint()*/

        onPaint: {
            //if (canvas.prepeared)
                var ctx = canvas.getContext('2d') //comment this line to make everything works well without timers
        }
    }
}

Particles.qml:

import QtQuick 2.7
import QtQuick.Particles 2.0

Item {
    id: root

    ParticleSystem { id: systemp }
    ImageParticle {
        system: systemp
        source: "qrc:///particleresources/star.png"
        color: "red"
        SequentialAnimation on color {
            loops: Animation.Infinite
            ColorAnimation {
                from: "red"
                to: "blue"
                duration: 1000
            }
            ColorAnimation {
                from: "blue"
                to: "red"
                duration: 1000
            }
        }
        colorVariation: 0.3
    }
    Emitter {
        id: trails
        system: systemp
        emitRate: 150
        lifeSpan: 750
        y: 0
        x: 0
        velocity: PointDirection {xVariation: 2; yVariation: 2;}
        acceleration: PointDirection {xVariation: 3; yVariation: 3;}
        velocityFromMovement: 5
        size: 10
        sizeVariation: 5
    }
}

我的解决方法您可以检查何时取消注释所有行。没有它 - &gt;在上面阅读。

更新

在Windows 8.1中使用相同的工具(mingw32,Qt5.7)发现了同样的问题。

0 个答案:

没有答案