Core: Fix handling of high dpi for self provided cursors

When using the cursors provided by QC we should scale them according
to the pixel ratio otherwise the icons appear too small.

Task-number: QTCREATORBUG-29980
Change-Id: Ia9de8a5adf4bbd457971260edc52f824ddb7564f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2024-02-29 15:31:15 +01:00
parent c87435f971
commit f35962cfb3

View File

@@ -8,6 +8,7 @@
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
#include <QApplication>
#include <QPaintEvent>
#include <QPainter>
#include <QSplitterHandle>
@@ -15,8 +16,14 @@
namespace Core {
namespace Internal {
static QBitmap scaledBitmap(const QBitmap &other, qreal factor)
{
QTransform trans = QTransform::fromScale(factor, factor);
return other.transformed(trans);
}
// cursor images / masks taken from qplatformcursor.cpp
static QCursor hsplitCursor()
static QCursor hsplitCursor(qreal ratio)
{
static const uchar hsplit_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -42,14 +49,13 @@ static QCursor hsplitCursor()
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static QBitmap cursorImg = QBitmap::fromData({32, 32}, hsplit_bits);
static QBitmap mask = QBitmap::fromData({32, 32}, hsplitm_bits);
static QCursor cursor(cursorImg, mask, 15, 15);
return cursor;
return QCursor(scaledBitmap(cursorImg, ratio), scaledBitmap(mask, ratio),
15 * ratio, 15 * ratio);
}
static QCursor vsplitCursor()
static QCursor vsplitCursor(qreal ratio)
{
static const uchar vsplit_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -77,8 +83,8 @@ static QCursor vsplitCursor()
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static QBitmap cursorImg = QBitmap::fromData({32, 32}, vsplit_bits);
static QBitmap mask = QBitmap::fromData({32, 32}, vsplitm_bits);
static QCursor cursor(cursorImg, mask, 15, 15);
return cursor;
return QCursor(scaledBitmap(cursorImg, ratio), scaledBitmap(mask, ratio),
15 * ratio, 15 * ratio);
}
class MiniSplitterHandle : public QSplitterHandle
@@ -109,10 +115,12 @@ using namespace Core::Internal;
bool MiniSplitterHandle::event(QEvent *event)
{
if (generalSettings().provideSplitterCursors()) {
if (event->type() == QEvent::HoverEnter)
setCursor(orientation() == Qt::Horizontal ? hsplitCursor() : vsplitCursor());
else if (event->type() == QEvent::HoverLeave)
if (event->type() == QEvent::HoverEnter) {
const qreal ratio = screen()->devicePixelRatio();
setCursor(orientation() == Qt::Horizontal ? hsplitCursor(ratio) : vsplitCursor(ratio));
} else if (event->type() == QEvent::HoverLeave) {
unsetCursor();
}
}
return QSplitterHandle::event(event);
}