From f35962cfb3a377f88de8e3855f2f0a3ad42f4b22 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 29 Feb 2024 15:31:15 +0100 Subject: [PATCH] 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 --- src/plugins/coreplugin/minisplitter.cpp | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/plugins/coreplugin/minisplitter.cpp b/src/plugins/coreplugin/minisplitter.cpp index dd2aa280e1f..cdf6d16d8e2 100644 --- a/src/plugins/coreplugin/minisplitter.cpp +++ b/src/plugins/coreplugin/minisplitter.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -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); }