// Unable to resize qt application according to some high resolution screen size ?
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickView>
#include <QScreen>
#include "rearend.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
//qmlRegisterType<RearEnd>("io.backside",1,0,"RearEnd");
QScreen *screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen->geometry();
int height = screenGeometry.height();
int width = screenGeometry.width();
qDebug() << "height = " << height;
qDebug() << "width = " << width;
QQmlApplicationEngine engine;
RearEnd *myClass = new RearEnd;
myClass->setHeight(height);
myClass->setWidth(width);
engine.rootContext()->setContextProperty("RearEnd", myClass);
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();
}
// I'm trying to create a qt application which can be deploy on any device of any resolution.So my qt application uses QScreen geometry() api and gets height and width of the primary screen.These values are then passed to qml where different components like layouts,layout alignment positions,rectangles , buttons etc resize themselves according to screen resolution.And the above code is working fine for many resolutions like 2048 x 1536, 1920 x 1080, 1680 x 1050, 800 x 600 etc.But they are not working for 2736 x 1824 and 2560 x 1600.I'm printing logs while I run my qt application.When I set resolution 1920 x 1080, it is showing me width = 1920 & height = 1080.But when I set resolution as 2736 x 1824 in logs it is showing width = 1368 & height = 912.Similarly when I set the resolution as 2560 x 1600, in logs it is showing width = 1280 & height = 800
I've figured out the solution.I commented this code "QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling)" & it worked for me.Seems there was some dpi issue which was not working for high end resolutions.