Compare commits

...

3 Commits

Author SHA1 Message Date
Laurent Trinques e202b5bc2b Merge pull request #475 from Kellermorph/update-german-translation
Update German translations for duplicate diagram feature
2026-05-31 16:05:45 +02:00
Laurent Trinques 2b7e62f901 [PATCH] print: fix black screen on macOS arm64 after PDF export
On macOS arm64 (Apple Silicon, Sequoia), exporting a PDF via
QPrintPreviewWidget leaves a black screen with only the mouse cursor
visible.  Cmd+Tab restores the display; the exported PDF itself is
correct and clickable cross-reference links work fine.

Root cause
----------
requestPaint() is a slot connected to QPrintPreviewWidget::paintRequested.
Inside this slot the code was calling painter.end() manually, then
pdfConvertUriToGoTo().  On macOS arm64 the Qt5 paint cycle backed by
Metal/CALayer is asynchronous: closing the QPainter from *within* the
paintRequested slot interrupts the compositor before it has flushed the
backing store.  The window goes black and never repaints because the
close() that follows immediately destroys it.

On x86_64 / older macOS (raster/CoreGraphics backend) the paint cycle is
synchronous, so the same code happened to work.

Fix
---
1. Remove the manual painter.end() and pdfConvertUriToGoTo() call from
   requestPaint().  The QPainter is stack-allocated; it destructs normally
   when the slot returns, which is the correct moment to flush the PDF.

2. In print(), capture the output file name before m_preview->print(),
   then defer both pdfConvertUriToGoTo() and this->close() to the next
   event-loop iteration via QTimer::singleShot(0, ...).  This gives the
   Metal compositor one full event-loop turn to finish compositing the
   backing store before the window is torn down.

The fix is a no-op on all other platforms: QTimer::singleShot(0) posts
an event that fires in the very next iteration, so there is no perceptible
delay.

Tested
------
- macOS Sequoia 15.x, Apple M-series, Qt 5.15.x (arm64): black screen gone
- macOS 10.15 x86_64 VM, Qt 5.15.x: no regression
- Linux/Debian Qt 5.15.x: no regression
- PDF cross-reference links and GoTo/FitR destinations: unaffected

Fixes: black screen after PDF export on macOS arm64
2026-05-31 13:01:52 +02:00
Kellermorph 23e8258ae1 Update German translations for duplicate diagram feature 2026-05-31 10:48:09 +02:00
3 changed files with 34 additions and 14 deletions
BIN
View File
Binary file not shown.
+5 -5
View File
@@ -2814,7 +2814,7 @@ Alle Bauteile und Unterordner von diesem Ordner werden ebenso gelöscht.</transl
<message> <message>
<location filename="../sources/elementspanelwidget.cpp" line="63"/> <location filename="../sources/elementspanelwidget.cpp" line="63"/>
<source>Copier et coller</source> <source>Copier et coller</source>
<translation type="unfinished"></translation> <translation>Kopieren und Einfügen</translation>
</message> </message>
<message> <message>
<location filename="../sources/elementspanelwidget.cpp" line="64"/> <location filename="../sources/elementspanelwidget.cpp" line="64"/>
@@ -8855,7 +8855,7 @@ Was möchten Sie tun?</translation>
<message> <message>
<location filename="../sources/ElementsCollection/fileelementcollectionitem.cpp" line="133"/> <location filename="../sources/ElementsCollection/fileelementcollectionitem.cpp" line="133"/>
<source>Makros</source> <source>Makros</source>
<translation type="unfinished"></translation> <translation>Vorlagen</translation>
</message> </message>
<message> <message>
<location filename="../sources/ElementsCollection/fileelementcollectionitem.cpp" line="135"/> <location filename="../sources/ElementsCollection/fileelementcollectionitem.cpp" line="135"/>
@@ -9420,15 +9420,15 @@ Möchten Sie sie ersetzen?</translation>
<translation>Einfügen</translation> <translation>Einfügen</translation>
</message> </message>
<message> <message>
<location filename="../sources/conductorproperties.cpp" line="826"/>
<location filename="../sources/ElementsCollection/elementslocation.cpp" line="401"/> <location filename="../sources/ElementsCollection/elementslocation.cpp" line="401"/>
<location filename="../sources/factory/elementpicturefactory.cpp" line="582"/>
<location filename="../sources/qetapp.cpp" line="2379"/>
<location filename="../sources/SearchAndReplace/searchandreplaceworker.cpp" line="351"/> <location filename="../sources/SearchAndReplace/searchandreplaceworker.cpp" line="351"/>
<location filename="../sources/SearchAndReplace/searchandreplaceworker.cpp" line="474"/> <location filename="../sources/SearchAndReplace/searchandreplaceworker.cpp" line="474"/>
<location filename="../sources/SearchAndReplace/searchandreplaceworker.cpp" line="509"/> <location filename="../sources/SearchAndReplace/searchandreplaceworker.cpp" line="509"/>
<location filename="../sources/SearchAndReplace/searchandreplaceworker.cpp" line="538"/> <location filename="../sources/SearchAndReplace/searchandreplaceworker.cpp" line="538"/>
<location filename="../sources/SearchAndReplace/ui/searchandreplacewidget.cpp" line="425"/> <location filename="../sources/SearchAndReplace/ui/searchandreplacewidget.cpp" line="425"/>
<location filename="../sources/conductorproperties.cpp" line="826"/>
<location filename="../sources/factory/elementpicturefactory.cpp" line="582"/>
<location filename="../sources/qetapp.cpp" line="2379"/>
<location filename="../sources/titleblock/templatelocation.cpp" line="108"/> <location filename="../sources/titleblock/templatelocation.cpp" line="108"/>
<source>this is an error in the code</source> <source>this is an error in the code</source>
<translation>dies ist ein Programmfehler</translation> <translation>dies ist ein Programmfehler</translation>
+28 -8
View File
@@ -47,6 +47,7 @@
#include <QFile> #include <QFile>
#include <QRegularExpression> #include <QRegularExpression>
#include <QMap> #include <QMap>
#include <QTimer>
#include <QVector> #include <QVector>
/** /**
@@ -495,13 +496,12 @@ void ProjectPrintWindow::requestPaint()
printDiagram(diagram, ui->m_fit_in_page_cb->isChecked(), &painter, m_printer, diagramPageMap); printDiagram(diagram, ui->m_fit_in_page_cb->isChecked(), &painter, m_printer, diagramPageMap);
} }
if (pdfExport) { // Note: do NOT call painter.end() or pdfConvertUriToGoTo() here.
painter.end(); // flush & close the PDF file on disk // We are inside the paintRequested slot: the QPrintPreviewWidget still
// Convert URI link annotations into native internal GoTo/FitR actions: // owns the paint cycle. On macOS arm64 (Metal/CALayer compositor),
// cross-references then jump inside the document (no new viewer // closing the QPainter manually inside this slot leaves the backing
// instance) and frame the target element. // store in an undefined state, producing a black screen after export.
pdfConvertUriToGoTo(m_printer->outputFileName()); // pdfConvertUriToGoTo() is deferred to print() via QTimer::singleShot(0).
}
} }
/** /**
@@ -1218,9 +1218,29 @@ void ProjectPrintWindow::on_m_uncheck_all_clicked()
void ProjectPrintWindow::print() void ProjectPrintWindow::print()
{ {
m_preview->print(); const bool isPdf = (m_printer->outputFormat() == QPrinter::PdfFormat);
const QString pdfFile = isPdf ? m_printer->outputFileName() : QString();
m_preview->print(); // triggers requestPaint() synchronously; painter
// is created/destroyed inside that call
savePageSetupForCurrentPrinter(); savePageSetupForCurrentPrinter();
if (isPdf && !pdfFile.isEmpty()) {
// Defer post-processing and window close to the next event-loop
// iteration. This lets the macOS arm64 Metal compositor finish
// compositing the backing store before the window is destroyed,
// which prevents the black screen observed on Apple Silicon under
// macOS Sequoia (QPrintPreviewWidget + CALayer timing issue).
QTimer::singleShot(0, this, [this, pdfFile]() {
// Convert URI link annotations into native internal GoTo/FitR
// actions so cross-references jump inside the document.
pdfConvertUriToGoTo(pdfFile);
this->close(); this->close();
});
} else {
this->close();
}
} }
void ProjectPrintWindow::on_m_date_cb_userDateChanged(const QDate &date) void ProjectPrintWindow::on_m_date_cb_userDateChanged(const QDate &date)