QT += core gui declarative
import QtQuick 1.0 Rectangle { width: 100 height: 62 }
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QtGui/QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); }; #endif // MAINWINDOW_H
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QtDeclarative/QDeclarativeView> #include <QGraphicsObject> #include <QtGui> #include <QDeclarativeContext> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: QDeclarativeView *ui; }; #endif // MAINWINDOW_H
#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { } MainWindow::~MainWindow() { }
#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // QML ui = new QDeclarativeView; ui->setSource(QUrl("qrc:/main.qml")); setCentralWidget(ui); ui->setResizeMode(QDeclarativeView::SizeRootObjectToView); } MainWindow::~MainWindow() { // QML delete ui; }
import QtQuick 1.0 Rectangle { width: 100 height: 62 }
import QtQuick 1.0 // Rectangle { width: 300 height: 300 anchors.fill: parent }
// Rectangle { id: button // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2; // width: 100 height: 30 // color: "gray" // Text { id: buttonLabel text: "" anchors.centerIn: parent; } // MouseArea { anchors.fill: parent id: mouseArea } }
import QtQuick 1.0 Rectangle { width: 300 height: 300 anchors.fill: parent // Rectangle { id: button // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2; // width: 100 height: 30 // color: "gray" // Text { id: buttonLabel text: "" anchors.centerIn: parent; } // MouseArea { anchors.fill: parent id: mouseArea } } }
// Rectangle { id: textinputRect // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2+40; // width: 100 height: 18 // color: "gray" TextInput { id: textinput objectName: "textinput" color: "#151515"; selectionColor: "blue" font.pixelSize: 12; width: parent.width-4 anchors.centerIn: parent focus: true text:"1" } }
import QtQuick 1.0 Rectangle { width: 300 height: 300 anchors.fill: parent // Rectangle { id: button // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2; // width: 100 height: 30 // color: "gray" // Text { id: buttonLabel text: "" anchors.centerIn: parent; } // MouseArea { anchors.fill: parent id: mouseArea } } // Rectangle { id: textinputRect // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2+40; // width: 100 height: 18 // color: "gray" TextInput { id: textinput objectName: "textinput" color: "#151515"; selectionColor: "blue" font.pixelSize: 12; width: parent.width-4 anchors.centerIn: parent focus: true text:"1" } } }
// Rectangle { id: memoRect // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2+70; // width: 100 height: 35 // color: "gray" TextEdit{ id: memo objectName: "memo" wrapMode: TextEdit.Wrap width:parent.width; readOnly:true } }
import QtQuick 1.0 Rectangle { width: 300 height: 300 anchors.fill: parent // Rectangle { id: button // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2; // width: 100 height: 30 // color: "gray" // Text { id: buttonLabel text: "" anchors.centerIn: parent; } // MouseArea { anchors.fill: parent id: mouseArea } } // Rectangle { id: textinputRect // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2+40; // width: 100 height: 18 // color: "gray" TextInput { id: textinput objectName: "textinput" color: "#151515"; selectionColor: "blue" font.pixelSize: 12; width: parent.width-4 anchors.centerIn: parent focus: true text:"1" } } // Rectangle { id: memoRect // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2+70; // width: 100 height: 35 // color: "gray" TextEdit{ id: memo objectName: "memo" wrapMode: TextEdit.Wrap width:parent.width; readOnly:true } } }
// Root = ui->rootObject(); // C++ QML, ++ window ui->rootContext()->setContextProperty("window", this);
#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // QML ui = new QDeclarativeView; ui->setSource(QUrl("qrc:/main.qml")); setCentralWidget(ui); ui->setResizeMode(QDeclarativeView::SizeRootObjectToView); // Root = ui->rootObject(); // C++ QML, ++ window ui->rootContext()->setContextProperty("window", this); } MainWindow::~MainWindow() { // QML delete ui; }
QObject *Root;// QML
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QtDeclarative/QDeclarativeView> #include <QGraphicsObject> #include <QtGui> #include <QDeclarativeContext> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: QDeclarativeView *ui; QObject *Root;// QML }; #endif // MAINWINDOW_H
Q_INVOKABLE void FunctionC();// C++ QML
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QtDeclarative/QDeclarativeView> #include <QGraphicsObject> #include <QtGui> #include <QDeclarativeContext> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); Q_INVOKABLE void FunctionC();// C++ QML private: QDeclarativeView *ui; QObject *Root;// QML }; #endif // MAINWINDOW_H
void MainWindow::FunctionC() { // QObject* textinput = Root->findChild<QObject*>("textinput"); // QObject* memo = Root->findChild<QObject*>("memo"); QString str;// // text str=(textinput->property("text")).toString(); int a; a=str.toInt();// a++;// 1 QString str2;// str2=QString::number(a);// // memo->setProperty("text", str+"+1="+str2); }
// MouseArea { anchors.fill: parent id: mouseArea }
// MouseArea { anchors.fill: parent id: mouseArea // window.FunctionC() onClicked: window.FunctionC() }
import QtQuick 1.0 Rectangle { width: 300 height: 300 anchors.fill: parent // Rectangle { id: button // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2; // width: 100 height: 30 // color: "gray" // Text { id: buttonLabel text: "" anchors.centerIn: parent; } // MouseArea { anchors.fill: parent id: mouseArea // window.FunctionC() onClicked: window.FunctionC() } } // Rectangle { id: textinputRect // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2+40; // width: 100 height: 18 // color: "gray" TextInput { id: textinput objectName: "textinput" color: "#151515"; selectionColor: "blue" font.pixelSize: 12; width: parent.width-4 anchors.centerIn: parent focus: true text:"1" } } // Rectangle { id: memoRect // // x: parent.width / 2 - button.width / 2; y: parent.height / 2 - button.height / 2+70; // width: 100 height: 35 // color: "gray" TextEdit{ id: memo objectName: "memo" wrapMode: TextEdit.Wrap width:parent.width; readOnly:true } } }
Source: https://habr.com/ru/post/138837/
All Articles