[Interest] Problem with font size on Android and High DPI
Nguyen Ngoc Thach Chau
chaupad at gmail.com
Thu Nov 15 16:04:41 CET 2018
QGuiApplication app(argc, argv);
QScreen *screen = app.screens()[0];
double dpi = screen->physicalDotsPerInch();
dpi-= dpi * 10/100;
if(dpi >= 640) dpi = dpi/640; //xxxhdpi
else if (dpi >= 480) dpi = dpi/480; //xxhdpi
else if (dpi >= 320) dpi = dpi/320; //xhdpi
else if (dpi >= 240) dpi = dpi/240; //hdpi
else if (dpi >= 160) dpi = dpi/160; //mdpi
else if (dpi >= 120) dpi = dpi/120; //ldpi
else{
dpi = 1;//ldpi
}
I used as above then multiply all font pixels with "dpi".
On Thu, Nov 15, 2018 at 9:42 PM Jérôme Godbout <godboutj at amotus.ca> wrote:
> That I don't known, I'm 100% Qml and I just apply this to my Control style
> at one place. Maybe there is a way to do this into the cascading widget
> style...
>
> -----Original Message-----
> From: Roman Wüger <roman.wueger at gmx.at>
> Sent: November 14, 2018 1:32 PM
> To: Jérôme Godbout <godboutj at amotus.ca>
> Cc: ekke <ekke at ekkes-corner.org>; interest at qt-project.org
> Subject: Re: [Interest] Problem with font size on Android and High DPI
>
> And then I need to go over all widgets and multiply the font scale with
> current font size?
>
> Regards
>
> > Am 14.11.2018 um 18:17 schrieb Jérôme Godbout <godboutj at amotus.ca>:
> >
> > Take care the pixel density is way different on a mobile device form a
> normal desktop window. You might need to adjust your sizing for many thing.
> I do the following, I develop on a particular device with REFERENCE SIZE:
> >
> > // Collect screen dimension
> > const QScreen* const screen = QGuiApplication::primaryScreen();
> > QRect rect = screen->geometry();
> > const qreal height = qMax(rect.width(), rect.height());
> > const qreal width = qMin(rect.width(), rect.height());
> > const qreal dpi = screen->logicalDotsPerInch();
> >
> > // Compute reference ratio
> > m_horizontal_scale = width / REFERENCE_WIDTH;
> > m_vertical_scale = height / REFERENCE_HEIGHT;
> > m_dpi_scale = dpi / REFERENCE_DPI;
> >
> > // Compute other element scale factor
> > m_font_scale = qMin(m_horizontal_scale / m_dpi_scale,
> m_vertical_scale / m_dpi_scale);
> >
> > This allow you to have a display that look like each other compare to
> screen size. It's maybe not what yo are looking for but might give you some
> idea to achieve what you are looking for.
> >
> > -----Original Message-----
> > From: Interest <interest-bounces+godboutj=amotus.ca at qt-project.org> On
> Behalf Of Roman Wüger
> > Sent: November 14, 2018 11:30 AM
> > To: ekke <ekke at ekkes-corner.org>
> > Cc: interest at qt-project.org
> > Subject: Re: [Interest] Problem with font size on Android and High DPI
> >
> > No, it is a QWidget application with Qt 5.12. I can’t switch to QtQuick
> because customer wants existing application to be ported to android tablet.
> >
> > Regards
> > Roman
> >
> >>> Am 14.11.2018 um 17:15 schrieb ekke <ekke at ekkes-corner.org>:
> >>>
> >>> Am 14.11.18 um 17:11 schrieb Roman Wüger:
> >>> Hello everyone,
> >>>
> >>> I enabled the High DPI option on an android tablet. However, the fonts
> are not resized at all and looks a way too small. I tried the other
> environment variables too, but the result is not as expected.
> >>>
> >>> Does anyone have a hint or how is that done normally?
> >>>
> >>> Regards
> >>> Roman
> >>> _______________________________________________
> >>> Interest mailing list
> >>> Interest at qt-project.org
> >>> http://lists.qt-project.org/mailman/listinfo/interest
> >>>
> >> what kind of application ?
> >>
> >> QtQuickControls2 ?
> >>
> >> ekke
> >>
> >> _______________________________________________
> >> Interest mailing list
> >> Interest at qt-project.org
> >> http://lists.qt-project.org/mailman/listinfo/interest
> >
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181115/b27e605d/attachment.html>
More information about the Interest
mailing list