Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML Property width height as a variable instead of const
Forum Update on Monday, May 27th 2025

QML Property width height as a variable instead of const

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 719 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Prasad_Socionext
    wrote on last edited by
    #1

    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

    ODБOïO 1 Reply Last reply
    0
    • P Prasad_Socionext

      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

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @Prasad_Socionext hi,
      you can expose your c++ properties to QML : one way is :http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html

      1 Reply Last reply
      3
      • P Offline
        P Offline
        Prasad_Socionext
        wrote on last edited by VRonin
        #3

        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();
        }
        
        1 Reply Last reply
        0
        • P Offline
          P Offline
          Prasad_Socionext
          wrote on last edited by
          #4

          @BHARATH_PTHINKS could you help me with this one? thanks

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved