Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. I'm trying to use the applyWidthRatio function from the cpp file to provide DelegateChoice width even though this function is working fine for other components but not for DelegateChoice.Can someone please help me with this?
Forum Updated to NodeBB v4.3 + New Features

I'm trying to use the applyWidthRatio function from the cpp file to provide DelegateChoice width even though this function is working fine for other components but not for DelegateChoice.Can someone please help me with this?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 133 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.
  • _ Offline
    _ Offline
    _.Poonam._
    wrote on last edited by
    #1

    List.qml
    import QtQuick 2.15import QtQuick.Layouts 1.15import QtQuick 2.14import Qt.labs.qmlmodels 1.0import TableModel 0.1
    Rectangle { id: _eventLogScr clip: true border.width: 6 width: scalable.applyWidthRatio(909) height: scalable.applyHeightRatio(470) TableView { id:tableView1 anchors.fill: parent columnSpacing: 1 rowSpacing: 1 clip: true model: TableModel {}

    delegate: DelegateChooser { id:delegateChooser DelegateChoice { column: 0; Rectangle{ color: "transparent" border.width: 5 implicitWidth: scalable.applyWidthRatio(72) implicitHeight: scalable.applyHeightRatio(50) Text {} } } DelegateChoice { column: 1; Rectangle{ color: "transparent" border.width: 5 implicitWidth: scalable.applyWidthRatio(149) implicitHeight: scalable.applyHeightRatio(50) Text { } } } DelegateChoice { column: 2; Rectangle{ color: "transparent" border.width: 5 implicitWidth: scalable.applyWidthRatio(170) implicitHeight: scalable.applyHeightRatio(50) Text { } } } } }}

    main.cpp
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    #include "theme.h"
    #include "tabelmodel.h"

    int main(int argc, char *argv[])
    {
        qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
        static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO";
        if (!qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO)
                && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR")
                && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR")
                && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) {
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        }
        QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
        Theme *scalable = new Theme();
        engine.rootContext()->setContextProperty("scalable", scalable);
        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();
    }

    theme.h#ifndef THEME_H
    #define THEME_H
    #include <QQmlPropertyMap>
    #include <QObject>
    #include <QGuiApplication>
    #include <QScreen>
    #include <QDebug>
    #include <iomanip>

    class Theme :public QObject
    {
        Q_OBJECT
    public:
        Theme();
        qreal refDpi;
        qreal refHeight;
        qreal refWidth;
        QRect rect;
        qreal height;
        qreal width;
        qreal dpi;

    qreal m_hratio;
        qreal m_ratioFont;
        qreal m_wratio;

    Q_INVOKABLE int applyFontRatio(const int value);
        Q_INVOKABLE int applyHeightRatio(const int value);
        Q_INVOKABLE int applyWidthRatio(const int value);
    };

    #endif // THEME_H

    theme.cpp
    #include "theme.h"

    Theme::Theme()
    {
        refDpi = 96.;
        refHeight = 600.;
        refWidth = 1024.;
        rect = QGuiApplication::primaryScreen()->geometry();
        qDebug()<<rect;
        height = rect.height();
        width = rect.width();
        dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
        qDebug()<<dpi;
        m_hratio = height/refHeight;
        m_wratio = width/refWidth;

    m_ratioFont = qMin(heightrefDpi/(dpirefHeight), widthrefDpi/(dpirefWidth));
    }
    int Theme::applyFontRatio(const int value)
    {
        return int(value * m_ratioFont);
    }
    int Theme::applyHeightRatio(const int value)
    {
        //qDebug()<<s<<" of height is: "<<(value * m_hratio)<< " Hratio: "<<m_hratio;
        return qMax(2, int(value * m_hratio));
    }
    int Theme::applyWidthRatio(const int value)
    {
        //qDebug()<<"Value is "<<value<<s<<"  of Width is: "<<(value * m_wratio)<< " Wratio: "<<m_hratio;
        return qMax(2, int(value * m_wratio));
    }

    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