diff options
author | Christian Stenger <christian.stenger@qt.io> | 2024-02-29 15:31:15 +0100 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2024-03-07 07:49:33 +0000 |
commit | f35962cfb3a377f88de8e3855f2f0a3ad42f4b22 (patch) | |
tree | bcf875d44d898f9cc09319b244eefde787512841 | |
parent | c87435f9713c768f75975ca80a9b83919172b5eb (diff) |
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>
-rw-r--r-- | src/plugins/coreplugin/minisplitter.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/plugins/coreplugin/minisplitter.cpp b/src/plugins/coreplugin/minisplitter.cpp index dd2aa280e1..cdf6d16d8e 100644 --- a/src/plugins/coreplugin/minisplitter.cpp +++ b/src/plugins/coreplugin/minisplitter.cpp @@ -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); } |