From 66a18ca17a926697ee800c1293e758476ea67c47 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 11 Oct 2020 22:12:32 +0200 Subject: [PATCH] added animation --- .../Qt_Performance_Benchmark.pro | 17 ++- Qt_Performance_Benchmark/main.cpp | 23 +++- Qt_Performance_Benchmark/main.qml | 51 +++++++ Qt_Performance_Benchmark/mainwindow.cpp | 15 --- Qt_Performance_Benchmark/mainwindow.h | 21 --- Qt_Performance_Benchmark/mainwindow.ui | 126 ------------------ Qt_Performance_Benchmark/qml.qrc | 5 + 7 files changed, 80 insertions(+), 178 deletions(-) create mode 100644 Qt_Performance_Benchmark/main.qml delete mode 100644 Qt_Performance_Benchmark/mainwindow.cpp delete mode 100644 Qt_Performance_Benchmark/mainwindow.h delete mode 100644 Qt_Performance_Benchmark/mainwindow.ui create mode 100644 Qt_Performance_Benchmark/qml.qrc diff --git a/Qt_Performance_Benchmark/Qt_Performance_Benchmark.pro b/Qt_Performance_Benchmark/Qt_Performance_Benchmark.pro index d01e364..34ba75e 100644 --- a/Qt_Performance_Benchmark/Qt_Performance_Benchmark.pro +++ b/Qt_Performance_Benchmark/Qt_Performance_Benchmark.pro @@ -1,6 +1,4 @@ -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +QT += quick CONFIG += c++11 @@ -9,14 +7,15 @@ CONFIG += c++11 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - main.cpp \ - mainwindow.cpp + main.cpp -HEADERS += \ - mainwindow.h +RESOURCES += qml.qrc -FORMS += \ - mainwindow.ui +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/Qt_Performance_Benchmark/main.cpp b/Qt_Performance_Benchmark/main.cpp index fd3e533..db8d3b8 100644 --- a/Qt_Performance_Benchmark/main.cpp +++ b/Qt_Performance_Benchmark/main.cpp @@ -1,11 +1,20 @@ -#include "mainwindow.h" - -#include +#include +#include int main(int argc, char *argv[]) { - QApplication a(argc, argv); - MainWindow w; - w.show(); - return a.exec(); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + const QUrl url(QStringLiteral("qrc:/main.qml")); + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + &app, [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) + QCoreApplication::exit(-1); + }, Qt::QueuedConnection); + engine.load(url); + + return app.exec(); } diff --git a/Qt_Performance_Benchmark/main.qml b/Qt_Performance_Benchmark/main.qml new file mode 100644 index 0000000..5c96112 --- /dev/null +++ b/Qt_Performance_Benchmark/main.qml @@ -0,0 +1,51 @@ +import QtQuick 2.12 +import QtQuick.Window 2.12 +import QtQuick.Controls 2.3 + +Window { + id: rootwin + width: 640 + height: 480 + visible: true + title: qsTr("Hello World") + + + Rectangle { + x: 20 + y: 20 + width: 100; height: 100 + color: "forestgreen" + + //NumberAnimation on x { id: ani; loops: Animation.Infinite; to: 250; duration: 1000 } + + NumberAnimation on x { id: ani; loops: Animation.Infinite; from: 0; to: 1000; duration: 5000 } + } + + + function onChecked(checked) { + + if (checked) { + ani.resume() + } else { + ani.pause() + } + } + + CheckBox { + id: checkBox + x: 78 + y: 200 + state: active + text: qsTr("Check Box") + onClicked: rootwin.onChecked(checked) + } + + + +} + +/*##^## +Designer { + D{i:0;formeditorZoom:2} +} +##^##*/ diff --git a/Qt_Performance_Benchmark/mainwindow.cpp b/Qt_Performance_Benchmark/mainwindow.cpp deleted file mode 100644 index 41a26bd..0000000 --- a/Qt_Performance_Benchmark/mainwindow.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) -{ - ui->setupUi(this); -} - -MainWindow::~MainWindow() -{ - delete ui; -} - diff --git a/Qt_Performance_Benchmark/mainwindow.h b/Qt_Performance_Benchmark/mainwindow.h deleted file mode 100644 index 4643e32..0000000 --- a/Qt_Performance_Benchmark/mainwindow.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -QT_BEGIN_NAMESPACE -namespace Ui { class MainWindow; } -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - ~MainWindow(); - -private: - Ui::MainWindow *ui; -}; -#endif // MAINWINDOW_H diff --git a/Qt_Performance_Benchmark/mainwindow.ui b/Qt_Performance_Benchmark/mainwindow.ui deleted file mode 100644 index d3a445b..0000000 --- a/Qt_Performance_Benchmark/mainwindow.ui +++ /dev/null @@ -1,126 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 800 - 600 - - - - MainWindow - - - - - - 140 - 70 - 281 - 251 - - - - - 20 - - - 20 - - - 20 - - - 20 - - - 90 - - - 6 - - - - - CheckBox - - - - - - - - - - - - - - - 9 - - - - Label - - - - - - - - - - Qt::Horizontal - - - - - - - - First - - - - - Second - - - - - - - - PushButton - - - - - - - 24 - - - - - - - - - - 0 - 0 - 800 - 23 - - - - - - - - diff --git a/Qt_Performance_Benchmark/qml.qrc b/Qt_Performance_Benchmark/qml.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/Qt_Performance_Benchmark/qml.qrc @@ -0,0 +1,5 @@ + + + main.qml + +