From 4f7340691ae889d0967bc142e6ecbf364ae8a486 Mon Sep 17 00:00:00 2001 From: Dieter Mayer Date: Mon, 27 Jul 2026 10:14:17 +0200 Subject: [PATCH] Restore two more Qt5-only code paths on Qt6 (parts list, print dialog) Two further empty Qt6 guard branches found by ispyisail in qelectrotech#553: - Element editor parts list: the QGraphicsItem* was only stored into the list item on Qt5, so on Qt6 selecting a part in the list silently stopped selecting it on the canvas. QVariant::fromValue() works on both (Qt itself declares the metatype), guard removed. - Print dialog: setEnabledOptions() is a Qt4-era API removed in Qt6; setOptions() is the modern spelling with the same replace-the-set semantics and exists on both, guard removed. Both builds (Qt 5.15.2 and Qt 6.11.1) compile clean. (cherry picked from commit 759d1c078e23664482850bad2e91d668b93aadcf) --- sources/editor/ui/qetelementeditor.cpp | 14 +++++--------- sources/print/projectprintwindow.cpp | 12 ++++-------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/sources/editor/ui/qetelementeditor.cpp b/sources/editor/ui/qetelementeditor.cpp index b09a9a047..ae8f24891 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -480,15 +480,11 @@ void QETElementEditor::fillPartsList() } } QListWidgetItem *qlwi = new QListWidgetItem(part_desc); - QVariant v; -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove - v.setValue(qgi); -#else -#if TODO_LIST -#pragma message("@TODO remove code for QT 6 or later") -#endif - qDebug()<<"Help code for QT 6 or later"; -#endif + // Qt declares the QGraphicsItem* metatype itself, so this + // works on Qt 5 and Qt 6 alike. Without the stored pointer + // the parts list loses its item association and selecting + // a part no longer selects it on the canvas. + QVariant v = QVariant::fromValue(qgi); qlwi -> setData(42, v); m_parts_list -> addItem(qlwi); qlwi -> setSelected(qgi -> isSelected()); diff --git a/sources/print/projectprintwindow.cpp b/sources/print/projectprintwindow.cpp index 49c560e5a..92ff56336 100644 --- a/sources/print/projectprintwindow.cpp +++ b/sources/print/projectprintwindow.cpp @@ -79,14 +79,10 @@ void ProjectPrintWindow::launchDialog(QETProject *project, QPrinter::OutputForma print_dialog.setWindowFlags(Qt::Sheet); #endif print_dialog.setWindowTitle(tr("Options d'impression", "window title")); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove - print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintShowPageSize); -#else -#if TODO_LIST -#pragma message("@TODO remove code for QT 6 or later") -#endif - qDebug()<<"Help code for QT 6 or later"; -#endif + // setOptions() is the modern spelling of the Qt4-era + // setEnabledOptions() (removed in Qt 6): replace the enabled + // option set with just PrintShowPageSize, on Qt 5 and 6 alike. + print_dialog.setOptions(QAbstractPrintDialog::PrintShowPageSize); if (print_dialog.exec() == QDialog::Rejected) { delete printer_; return;