Custom cursor scaling with windows accessibility settings

Viewed 188

I have implemented 32x32 custom cursors with bitmaps using the following approach (in Qt 6.1.1):

this->setCursor(QCursor(QBitmap(":/Cursors/arrow_up.bmp"), QBitmap(":/Cursors/arrow_up_mask.bmp"), 3, 0));

The cursors work as expected if the Windows display setting for size of apps and text is set to 100%. However, if the size of apps and text setting is increased, Qt scales up the custom cursors accordingly and they become pixelated (e.g. if 150% is selected, Qt increases the size of the custom cursors by 50%).

Is there a way to prevent Qt from resizing the custom cursors? Alternatively, is there a way to know what the user has selected in Windows for the size of apps and text, so that I can provide cursors at the correct resolution?

1 Answers

Try this :

QCursor cursor = QCursor(QIcon(":/Cursors/arrow_up.bmp").pixmap(32, 32), 0, 0);
this->setCursor(cursor);

means that use QIcon instead of QBitmap and set its size by pixmap(32, 32).

Another things that may help you :

put this line in your main.cpp file :

QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

Read this Document . As I understand setting AA_EnableHighDpiScaling flag Enables high-DPI scaling in Qt on supported platforms (see also High DPI Displays). Supported platforms are X11, Windows and Android. Enabling makes Qt scale the main (device independent) coordinate system according to display scale factors provided by the operating system. This corresponds to setting the QT_AUTO_SCREEN​_SCALE_FACTOR environment variable to 1.

Related