#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QApplication>#include <QtDeclarative/QDeclarativeView>#include <QtCore/QUrl>#include <QDeclarativeContext>namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0); ~MainWindow();private slots: void on_pushButton_clicked(); void inslaider(int);private: Ui::MainWindow *ui; QDeclarativeView *ua;signals: void slmove(int);};#endif // MAINWINDOW_H
#include "mainwindow.h"#include "ui_mainwindow.h"#include <QHBoxLayout>#include <QProcess>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ //установка рисунка на слой виджета в интерфейсе ui->setupUi(this); ua = new QDeclarativeView; ua->setSource(QUrl("qrc:/tor.qml")); ua->setResizeMode(QDeclarativeView::SizeRootObjectToView); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(ua); ui->widget->setLayout(layout); }MainWindow::~MainWindow(){ delete ui; delete ua;}
Rectangle{ id: rect_lhzv objectName: "lverh" color: "red" x: 20 y: 217 width: 100 height: 1 } Rectangle{ id: rect_lhzn objectName: "lniz" color: "red" x: 20 y: 224 width: 100 height: 1 }
C++ (Qt)#include <QGuiApplication>#include <QQuickView> int main(int argc, char *argv[]){ QGuiApplication app(argc, argv); QQuickView view; view.setSource(QUrl::fromLocalFile("application.qml")); view.show(); QObject *object = view.rootObject(); QObject *rect = object->findChild<QObject*>("rect"); if (rect) rect->setProperty("color", "red"); return app.exec();}
C++ (Qt) view = new QQuickView(); view_container = createWindowContainer( view, widget ); widget->layout()->addWidget( view_container );
QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
ui->setupUi(this); QQuickView *view = new QQuickView; view->setSource(QUrl("qrc:/main.qml")); QWidget *container = QWidget::createWindowContainer(view); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(container); ui->widget->setLayout(layout);
C++ (Qt)QObject *object = static_cast<QObject *> (view.rootObject());
view->rootContext()->setContextProperty("rv",VAL); view->setSource(QUrl("qrc:/main.qml"));