Skip to content

Commit 7f3091b

Browse files
committed
src/definition/structuredrichtext: use primary screen when current null
When the current screen is null, use the primary screen from QGuiApplication to get the DPI. This fixes the first result being rendered with the wrong DPI in most cases. It is kind of hard to fix in cases where screens with multiple DPIs are mixed and matched, but those are niche. This works in the general case. This commit was written by Codex and edited by me.
1 parent 8c141a4 commit 7f3091b

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/definition/structuredrichtext.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <algorithm>
2424
#include <cmath>
2525

26+
#include <QGuiApplication>
2627
#include <QJsonObject>
2728
#include <QQuickWindow>
2829
#include <QSet>
@@ -2071,7 +2072,11 @@ double StructuredRichText::screenDpi(const QScreen *screen) const
20712072

20722073
if (screen == nullptr)
20732074
{
2074-
return DEFAULT_SCREEN_DPI;
2075+
screen = QGuiApplication::primaryScreen();
2076+
if (screen == nullptr)
2077+
{
2078+
return DEFAULT_SCREEN_DPI;
2079+
}
20752080
}
20762081
const double dpi = screen->logicalDotsPerInch();
20772082
return dpi > 0.0 ? dpi : DEFAULT_SCREEN_DPI;

0 commit comments

Comments
 (0)