From d1e60e0cdc4e650842d86edd39d4896d5615153b Mon Sep 17 00:00:00 2001 From: Shriram Vasudevan <72285290+Shriram-Vasudevan@users.noreply.github.com> Date: Mon, 11 May 2026 09:50:58 -0400 Subject: [PATCH 1/2] Fix note list rendering at fractional scaling --- src/main.cpp | 3 +++ src/notelistdelegate.cpp | 6 +++--- src/notelistdelegateeditor.cpp | 6 +++--- src/utils.h | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 60c18ede..460e771a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,9 +8,12 @@ #include "singleinstance.h" #include #include +#include int main(int argc, char *argv[]) { + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + QApplication app(argc, argv); // Set application information QApplication::setApplicationName("Notes"); diff --git a/src/notelistdelegate.cpp b/src/notelistdelegate.cpp index b96c151f..24a1daeb 100644 --- a/src/notelistdelegate.cpp +++ b/src/notelistdelegate.cpp @@ -294,11 +294,11 @@ QTimeLine::State NoteListDelegate::animationState() void NoteListDelegate::paintBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { auto bufferSize = bufferSizeHint(option, index); - QPixmap buffer{ bufferSize }; + QPixmap buffer = utils::makeDevicePixelRatioPixmap(bufferSize, m_view); buffer.fill(Qt::transparent); QPainter bufferPainter{ &buffer }; bufferPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - QRect bufferRect = buffer.rect(); + QRect bufferRect{ QPoint{}, bufferSize }; auto isPinned = index.data(NoteListModel::NoteIsPinned).toBool(); auto const *model = static_cast(m_view->model()); if (model->hasPinnedNote() && model->isFirstPinnedNote(index) && static_cast(m_view)->isPinnedNotesCollapsed()) { @@ -419,7 +419,7 @@ void NoteListDelegate::paintLabels(QPainter *painter, const QStyleOptionViewItem { if (m_animatedIndexes.contains(index)) { auto bufferSize = bufferSizeHint(option, index); - QPixmap buffer{ bufferSize }; + QPixmap buffer = utils::makeDevicePixelRatioPixmap(bufferSize, m_view); buffer.fill(Qt::transparent); QPainter bufferPainter{ &buffer }; bufferPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); diff --git a/src/notelistdelegateeditor.cpp b/src/notelistdelegateeditor.cpp index a34245f2..48f1ef2d 100644 --- a/src/notelistdelegateeditor.cpp +++ b/src/notelistdelegateeditor.cpp @@ -135,11 +135,11 @@ NoteListDelegateEditor::~NoteListDelegateEditor() void NoteListDelegateEditor::paintBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { auto bufferSize = rect().size(); - QPixmap buffer{ bufferSize }; + QPixmap buffer = utils::makeDevicePixelRatioPixmap(bufferSize, this); buffer.fill(Qt::transparent); QPainter bufferPainter{ &buffer }; bufferPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - QRect bufferRect = buffer.rect(); + QRect bufferRect{ QPoint{}, bufferSize }; auto const *noteListModel = static_cast(m_view->model()); if (noteListModel->hasPinnedNote() && (noteListModel->isFirstPinnedNote(index) || noteListModel->isFirstUnpinnedNote(index))) { int fifthYOffset = 0; @@ -375,7 +375,7 @@ bool NoteListDelegateEditor::underMouseC() const QPixmap NoteListDelegateEditor::renderToPixmap() { - QPixmap result{ rect().size() }; + QPixmap result = utils::makeDevicePixelRatioPixmap(rect().size(), this); result.fill(Qt::yellow); QPainter painter(&result); painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); diff --git a/src/utils.h b/src/utils.h index 4b091d46..eec70351 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,8 +1,13 @@ #pragma once +#include #include -#include #include +#include +#include +#include +#include +#include namespace utils { @@ -44,4 +49,29 @@ inline QString parseDateTime(const QDateTime &dateTime) return dateTime.date().toString("M/d/yy"); } -} // namespace utils \ No newline at end of file +inline qreal devicePixelRatioForWidget(const QWidget *widget) +{ + if (widget != nullptr) { + if (auto *topLevelWindow = widget->window(); (topLevelWindow != nullptr) && (topLevelWindow->windowHandle() != nullptr)) { + return topLevelWindow->windowHandle()->devicePixelRatio(); + } + + return widget->devicePixelRatioF(); + } + + if (auto *screen = QGuiApplication::primaryScreen(); screen != nullptr) { + return screen->devicePixelRatio(); + } + + return qreal(1); +} + +inline QPixmap makeDevicePixelRatioPixmap(const QSize &logicalSize, const QWidget *widget) +{ + const qreal scale = devicePixelRatioForWidget(widget); + QPixmap pixmap(logicalSize * scale); + pixmap.setDevicePixelRatio(scale); + return pixmap; +} + +} // namespace utils From 404e7cf8dedf640b9e828d06021fc71a492e365e Mon Sep 17 00:00:00 2001 From: Shriram Vasudevan <72285290+Shriram-Vasudevan@users.noreply.github.com> Date: Mon, 11 May 2026 21:27:44 -0400 Subject: [PATCH 2/2] Format DPI buffer initializers --- src/notelistdelegate.cpp | 2 +- src/notelistdelegateeditor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/notelistdelegate.cpp b/src/notelistdelegate.cpp index 24a1daeb..83f78549 100644 --- a/src/notelistdelegate.cpp +++ b/src/notelistdelegate.cpp @@ -298,7 +298,7 @@ void NoteListDelegate::paintBackground(QPainter *painter, const QStyleOptionView buffer.fill(Qt::transparent); QPainter bufferPainter{ &buffer }; bufferPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - QRect bufferRect{ QPoint{}, bufferSize }; + QRect bufferRect{ QPoint{ }, bufferSize }; auto isPinned = index.data(NoteListModel::NoteIsPinned).toBool(); auto const *model = static_cast(m_view->model()); if (model->hasPinnedNote() && model->isFirstPinnedNote(index) && static_cast(m_view)->isPinnedNotesCollapsed()) { diff --git a/src/notelistdelegateeditor.cpp b/src/notelistdelegateeditor.cpp index 48f1ef2d..9925623e 100644 --- a/src/notelistdelegateeditor.cpp +++ b/src/notelistdelegateeditor.cpp @@ -139,7 +139,7 @@ void NoteListDelegateEditor::paintBackground(QPainter *painter, const QStyleOpti buffer.fill(Qt::transparent); QPainter bufferPainter{ &buffer }; bufferPainter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - QRect bufferRect{ QPoint{}, bufferSize }; + QRect bufferRect{ QPoint{ }, bufferSize }; auto const *noteListModel = static_cast(m_view->model()); if (noteListModel->hasPinnedNote() && (noteListModel->isFirstPinnedNote(index) || noteListModel->isFirstUnpinnedNote(index))) { int fifthYOffset = 0;