From ecd3675aaa55b8224f1fa81b031471d834a18fad Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Mon, 20 Nov 2023 14:16:18 +0100 Subject: views: Use scene devicePixelRatio rather than qApp When possible, use the devicePixelRatio from the scene which on Wayland unlike the QApplication will properly support fractional scaling. A KItemViewsUtils class is introduced that can be reused elsewhere. --- src/kitemviews/private/kitemviewsutils.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/kitemviews/private/kitemviewsutils.cpp (limited to 'src/kitemviews/private/kitemviewsutils.cpp') diff --git a/src/kitemviews/private/kitemviewsutils.cpp b/src/kitemviews/private/kitemviewsutils.cpp new file mode 100644 index 000000000..9e343b6d0 --- /dev/null +++ b/src/kitemviews/private/kitemviewsutils.cpp @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2023 Kai Uwe Broulik + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "kitemviewsutils.h" + +#include +#include +#include +#include + +qreal KItemViewsUtils::devicePixelRatio(const QGraphicsItem *item) +{ + qreal dpr = qApp->devicePixelRatio(); + if (item->scene()) { + if (const auto views = item->scene()->views(); !views.isEmpty()) { + dpr = views.first()->devicePixelRatioF(); + } + } + return dpr; +} -- cgit v1.3