QML Property width height as a variable instead of const
Unsolved
General and Desktop
-
Hi
I want to fix the width, height, color, no of Tabs or panels needed from a UI_settings file which is a C++ files , any hints on how this can be done am new to QT QML
-
@Prasad_Socionext hi,
you can expose your c++ properties to QML : one way is :http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html -
This is my main.qml
ApplicationWindow { id:start_gui visible: true width:1200 height: 800 title: qsTr("Start GUI")
ui_settings.cpp
#include "ui_settings.h" #include "qdebug.h" #include <qqmlengine.h> #include <QtQuick/QQuickView> #include <QtQuick/QQuickItem> Ui_Settings::Ui_Settings(QObject *parent) : QObject(parent) { } const int gui_width = 1200; const int gui_height = 800;
ui_settings.h
#ifndef UI_SETTINGS_H #define UI_SETTINGS_H #include <QObject> class Ui_Settings: public QObject { public: explicit Ui_Settings(QObject *parent = nullptr); private: Q_INVOKABLE static const int gui_width = 1200; Q_INVOKABLE static const int gui_height = 800; }; #endif // UI_SETTINGS_H
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <qqmlengine.h> #include <qqmlcontext.h> #include <qqml.h> #include <QStringList> #include "connect_serial_port.h" #include "tcpip_client.h" #include "fileio.h" #include "ui_settings.h" int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); qmlRegisterType<FileIO, 1>("FileIO", 1, 0, "FileIO"); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; Connect_Serial_Port connect_serial_port; Tcpip_Client tcpip_client; Ui_Settings ui_settings; QQmlContext *classContext = engine.rootContext(); classContext->setContextProperty("connect_serial_port", &connect_serial_port); classContext->setContextProperty("tcpip_client", &tcpip_client); classContext->setContextProperty("ui_settings",&ui_settings); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; connect_serial_port.scan_for_ports(); return app.exec(); }
-
@BHARATH_PTHINKS could you help me with this one? thanks