Skip to content
  • 0 Votes
    2 Posts
    284 Views
    S

    @Sammasas
    I didn't find a universal way, but with an QJNIObject and objective c it works now. Java with JNiObject:

    package Klingelball; import android.content.Context; import android.content.res.Configuration; import android.util.DisplayMetrics; import android.view.WindowManager; public class AndroidSettings { public static float getFontScale(Context context) { //return getResources().getConfiguration().fontScale; Configuration configuration = context.getResources().getConfiguration(); // Get the font scale from the configuration float fontScale = configuration.fontScale; return fontScale; } }

    It's important that the file is under src/mypackage.

    .cpp file:

    #ifdef Q_OS_ANDROID QJniObject context = QNativeInterface::QAndroidApplication::context(); if(QJniObject::isClassAvailable("Klingelball/AndroidSettings")) { QJniObject androidSettingsJavaObject = QJniObject("Klingelball/AndroidSettings"); fontScale = new float(androidSettingsJavaObject.callStaticMethod<jfloat>("Klingelball/AndroidSettings", "getFontScale", "(Landroid/content/Context;)F", context.object<jobject>())); qDebug() <<"Font scale:" << *fontScale; setup_fontAndroid(*fontScale); } else { qDebug() << "JAVA CLASS UNAVAIABLE!"; fontScale = new float(1); setup_fontAndroid(*fontScale); } #endif

    iOs with objective-c:
    .mm file:

    include "iOSSettings.h" #include <UIKit/UIKit.h> int iOSSettings::getPrefferedFont() { return [UIFont preferredFontForTextStyle:UIFontTextStyleBody].pointSize; }

    .h file:

    class iOSSettings { public: static int getPrefferedFont(); };

    .cpp file:

    #ifdef Q_OS_IOS fontScale = new float(getfontScalefrompointSize(iOSSettings::getPrefferedFont())); setup_fontiOS(iOSSettings::getPrefferedFont()); #endif

    iOS returns the preffered Fontsize, I implemented a function that returns a factor based on the fontsize because I had to scale the Icons too.
    Hope this helps somebody :)

  • 1 Votes
    2 Posts
    584 Views
    S

    It's probably the same as https://bugreports.qt.io/browse/QTBUG-90634

  • 0 Votes
    15 Posts
    9k Views
    V

    Found the proper option: QT_ENABLE_HIGHDPI_SCALING=0.

  • 0 Votes
    3 Posts
    680 Views
    Guy GizmoG

    I'm afraid that doesn't help for my use case, since I need the images to appear as clear and clean as possible when being scaled down.

  • 0 Votes
    1 Posts
    190 Views
    No one has replied
  • 0 Votes
    3 Posts
    2k Views
    J

    In one of my project, a bit of resolution seems to be lost when scaling (150%). It is plotting a complicated graph for signal processing. We are thinking whether we can just plot the graph according to the scaling factor (e.g. running the math calculation ourslef and generate a graph double the size for high resolution etc) and not to scale this part of the widget by using the high dpi setting.

  • 0 Votes
    2 Posts
    423 Views
    D

    The code to fix this problem was really unexpected and quite time consuming. The kicker is that QGuiApplication.devicePixelRatio() always returns 1.0 under Gnome, regardless of what scaling is actually set to. That means Gdk must be called to determine the scaling value.

    import gi gi.require_version('Gdk', '3.0') from gi.repository import Gdk def any_screen_scaled_gdk() -> bool: """ Detect if any of the screens on this system have scaling enabled. Uses GDK to do the querying. :return: True if found, else False """ try: display = Gdk.Display.get_default() except Exception: import logging logging.exception( 'An unexpected error occurred when querying the systems display parameters. Exception:' ) return False if display: try: for n in range(display.get_n_monitors()): monitor = display.get_monitor(n) if monitor.get_scale_factor() > 1: return True return False except AttributeError: # get_n_monitors() was introduced in gtk 3.22 try: screen = display.get_default_screen() for monitor in range(screen.get_n_monitors()): if screen.get_monitor_scale_factor(monitor) > 1: return True except Exception: import logging logging.exception('An unexpected error occurred when querying Gdk. Exception:') return False def any_screen_scaled_qt() -> bool: """ Detect if any of the screens on this system have scaling enabled. Call before QApplication is initialized. Uses temporary QGuiApplication. :return: True if found, else False """ app = QGuiApplication(sys.argv) return app.devicePixelRatio() > 1.0
  • 1 Votes
    6 Posts
    2k Views
    Y

    @Maikkannan said in How to fix scaling issue in Qt desktop application.:

    increased

    Do you run it on a 2K screen?

  • 0 Votes
    6 Posts
    1k Views
    Y

    Finally. This code works fine.

    void onPrint(QPrinter* printer) { QPagedPaintDevice* device = printer; QPainter painter; painter.begin(device); int w = device->width(); int h = device->height(); painter.drawLine(0,0,w,h); painter.drawLine(0,h,w,0); painter.drawEllipse(QPointF(w/2, h/2), w/10, w/10); painter.drawText(0, h, "pixels"); printer->newPage(); painter.end(); }
  • 0 Votes
    2 Posts
    3k Views
    SGaistS

    Hi,

    Did you already saw the related part of QIcon’s documentation ?

  • 0 Votes
    2 Posts
    770 Views
    ?

    Hi! Have you seen the Qt 3D: Planets QML Example?

  • 0 Votes
    4 Posts
    1k Views
    J

    In C++ you register your image provider by providing a new resource prefix (say you chose "myimage") then in QML it will look like this:

    source: "myimage://myborderImage"

    Read Qt doc about QQuickImageProvider class, there is an example of how to use it

  • 0 Votes
    4 Posts
    1k Views
    R

    @johngod Thank you so much, you're right Screen.pixelDensity would be the complete solution if it was in qml,
    sifting trough the qt source i was able that it was derived from:

    double pixelpermm = QGuiApplication::primaryScreen()->physicalDotsPerInch() / 25.4 //physicalDotsPerInchX() & physicalDotsPerInchY() also exist

    and it seems to be correct on both my iPhone & iPad quite wel (better than all other ways I found so far)

    @Lorenz thanks, but for the time being I want to stick to Qt as it is a paid sdk as soon as you go commercial

  • 0 Votes
    3 Posts
    3k Views
    SGaistS

    Hi and welcome to devnet,

    I'd recommend posting this question to the Qt Creator mailing list. You'll find there Qt Creator's developers/maintainers. This forum is more user oriented.

  • 0 Votes
    6 Posts
    2k Views
    V

    ok will do

  • 0 Votes
    1 Posts
    648 Views
    No one has replied
  • 0 Votes
    3 Posts
    2k Views
    vikramgV

    I have been looking into this myself, with no conclusive information on how to reliably accomplish this. It feels like Qt 5.6 ought to automagically do the scaling for you; I intend to post a new question in this forum asking about this. In the meanwhile, the first part of this video will be of interest to you:

    https://youtu.be/nNyhsdX6BsI?t=6m24s

    There is code at 06:24 that extracts the dpi value from the Android framework. Maybe that will work better, I have not tried it myself.

  • 0 Votes
    2 Posts
    1k Views
    ekkescornerE

    icons depend on DevicePixelRatio and are named this way:

    myIcon.png - corresponds to 1.0 and mdpi - use this name in qml
    myIcon@2x.png - 2.0 and xhdpi
    myIcon@3x.png - 3.0 and xxhdpi
    myIcon@4x.png - 4.0 and xxxhdpi

    if you want to know the DevicePixelRatio:

    C++
    qApp->primaryScreen()......

  • 0 Votes
    12 Posts
    3k Views
    SGaistS

    Thanks !

  • 0 Votes
    4 Posts
    36k Views
    G

    Thank you. Both worked though I guess it is supposed to be

    int w = ui->label->width (); int h = ui->label->height (); ui->label->setPixmap (pix.scaled (w,h,Qt::KeepAspectRatio));