I made this situations as simple as possible: I am creating Item/Window/Rectangle/whatever that contains customized particle system.
Window {
MyParticles {
anchors.fill: parent
}
}
And I have also an item that uses canvas inside itself:
Item {
Canvas {
anchors.fill: parent
onPaint: {
var ctx = canvas.getContext('2d') //without that line everything works fine
//nothing further
}
}
}
If I have them together (inside one parent, inside different parents that have one common parent), Particle system wont appear until I will play with the window (resizing alot in 5-7 seconds), that contains their common parent. If I won't touch this, Particles will work (console.log), but I will not be able to see them at all. It seems like when I am resizing the window or minimize & show back, I am calling something like "repaint" in the window and it's children. It only happens, when I am having item with Canvas. All other items works well with those Particles. Qt5.7, mingw32, Windows 7. Btw, same code works like a charm under Mac OS Sierra. How to fix this?
UPDATE
As was suggested: pro file:
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
}
}
My workaround You can check when You uncomment all lines. Without it-> read above.
UPDATE
Same issue was discovered in Windows 8.1 with same tools (mingw32, Qt5.7).