import QtQuick 2.2Rectangle { id: root width: 800 height: 800 Component { id: termitClass Rectangle { id: termit height: 10 width: 30 color: "green" opacity: 0.5 property bool textFlag: true property real dx: 0 property real dy: 0 property int interval: 400 Text { anchors.centerIn: parent text: (textFlag) ? "Муравей" : "Я бегу" font.pixelSize: 6 color: "white" } Timer { interval: termit.interval onTriggered: termit.move(); running: true repeat: true } Timer { interval: 5000 onTriggered: termit.check(); running: true repeat: true } function move() { termit.x = termit.x+dx; termit.y = termit.y+dy; textFlag = !textFlag; } function check() { termit.dx = termit.dx*-1; termit.dy = termit.dy*-1; } } } Component.onCompleted: { for (var i=0; i<5000; i++) { var nx = Math.random()*root.width; var ny = Math.random()*root.height; var interval = Math.random()*400+200; termitClass.createObject(root, {"x": nx, "y": ny, "dx": Math.random()*4-2, "dy": Math.random()*4-2, "interval": interval}); } }}
import QtQuick 2.3import QtQuick.Controls 1.2ApplicationWindow { visible: true width: 800 height: 800 title: qsTr("Hello World") menuBar: MenuBar { Menu { title: qsTr("File") MenuItem { text: qsTr("&Open") onTriggered: console.log("Open action triggered"); } MenuItem { text: qsTr("Exit") onTriggered: Qt.quit(); } } } Rectangle { id: root width: 800 height: 800 anchors.centerIn: parent color: "grey" Component { id: termitClass Rectangle { id: termit height: 20 width: 80 color: "green" border.color: "black" clip: true opacity: 0.5 property bool textFlag: true property real dx: 0 property real dy: 0 property int interval: 400 Text { id: termitInfo anchors.centerIn: parent //text: (textFlag) ? "Муравей" : "Я бегу" font.pixelSize: 10 color: "white" } Timer { interval: termit.interval onTriggered: termit.move(); running: true repeat: true } Timer { interval: 5000 onTriggered: termit.check(); running: true repeat: true } function move() { termit.x = termit.x+dx; termit.y = termit.y+dy; textFlag = !textFlag; termitInfo.text = "x:" + x.toFixed(2) + " y:" + y.toFixed(2); } function check() { termit.dx = termit.dx*-1; termit.dy = termit.dy*-1; } } } Component.onCompleted: { for (var i=0; i<5000; i++) { var nx = Math.random()*root.width; var ny = Math.random()*root.height; var interval = Math.random()*400+200; termitClass.createObject(root, {"x": nx, "y": ny, "dx": Math.random()*4-2, "dy": Math.random()*4-2, "interval": interval}); } } } MouseArea { anchors.fill: parent onWheel: { if (wheel.angleDelta.y > 0) { root.width += 10; root.height += 10; } else { root.width -= 10; root.height -= 10; } } }}
painEvent...{ QPainter p(this); p.setOpacity(0.5); p.setBrush(Qt::green); for(int i=0; i<800; i++) { p.drawRect(0,0,80,20); p.drawText(QRect(0,0,80,20),"FPS: 100500"); } fpsCounter++; p.drawText(50,50,QString::number(fps));}