From f8499cb09ef36acf4d051c29b9a1e50dc4f19356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Fri, 13 Nov 2026 14:39:12 +0100 Subject: [PATCH] enable qt5 --- .gitea/workflows/docker-rh8-build-rpm.yml | 3 +++ .gitea/workflows/docker-rh9-build-rpm.yml | 2 ++ CMakeLists.txt | 9 ++++--- slsDetectorGui/CMakeLists.txt | 25 +++++++++++++++---- .../include/SlsQtPlotCommon.h | 12 +++++++++ .../slsDetectorPlotting/src/SlsQt1DPlot.cpp | 4 +-- .../src/SlsQtFastImage.cpp | 10 ++++---- .../src/SlsQtScalePanel.cpp | 10 ++++---- slsDetectorGui/src/qDetectorMain.cpp | 5 ++++ slsDetectorGui/tests/CMakeLists.txt | 4 +-- slsDetectorGui/tests/plotting_test.cpp | 5 ++++ 11 files changed, 66 insertions(+), 23 deletions(-) diff --git a/.gitea/workflows/docker-rh8-build-rpm.yml b/.gitea/workflows/docker-rh8-build-rpm.yml index 8ac0aa501..53d4251be 100644 --- a/.gitea/workflows/docker-rh8-build-rpm.yml +++ b/.gitea/workflows/docker-rh8-build-rpm.yml @@ -25,6 +25,7 @@ jobs: - name: Install build dependencies run: | + # RHEL8 has no Qt6, the gui is built with Qt5 dnf -y install rpm-build qt5-qtbase-devel qt5-qtsvg-devel \ libpng-devel zlib-devel expat-devel libtiff-devel @@ -33,8 +34,10 @@ jobs: cmake -S . -B build \ -DCMAKE_BUILD_TYPE=Release \ -DSLS_USE_GUI=ON \ + -DCMAKE_DISABLE_FIND_PACKAGE_Qt6=ON \ -DSLS_USE_MOENCH=ON \ -DSLS_INSTALL_VERSIONED_BINARIES=ON + grep -q '^Qt5_DIR:PATH=/' build/CMakeCache.txt cmake --build build -j 2 - name: Build RPMs diff --git a/.gitea/workflows/docker-rh9-build-rpm.yml b/.gitea/workflows/docker-rh9-build-rpm.yml index f8ff86647..2de9edb2c 100644 --- a/.gitea/workflows/docker-rh9-build-rpm.yml +++ b/.gitea/workflows/docker-rh9-build-rpm.yml @@ -32,6 +32,8 @@ jobs: -DSLS_USE_GUI=ON \ -DSLS_USE_MOENCH=ON \ -DSLS_INSTALL_VERSIONED_BINARIES=ON + # Qt6, not a fallback to Qt5 + grep -q '^Qt6_DIR:PATH=/' build/CMakeCache.txt cmake --build build -j 2 - name: Build RPMs diff --git a/CMakeLists.txt b/CMakeLists.txt index f6a708fe3..bc6e6384c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -538,9 +538,12 @@ set(CPACK_RPM_PACKAGE_RELEASE_DIST ON) set(CPACK_RPM_COMPONENT_INSTALL ON) -set(CPACK_RPM_GUI_PACKAGE_REQUIRES - "qt6-qtbase, qt6-qtbase-gui" -) +# The Qt the gui was built with, Qt5 on RHEL8 and Qt6 on RHEL9 +if(SLS_QT STREQUAL "Qt5") + set(CPACK_RPM_GUI_PACKAGE_REQUIRES "qt5-qtbase, qt5-qtbase-gui") +else() + set(CPACK_RPM_GUI_PACKAGE_REQUIRES "qt6-qtbase, qt6-qtbase-gui") +endif() #control which RPMs are generated set(CPACK_COMPONENTS_ALL cli receiver zmq gui) diff --git a/slsDetectorGui/CMakeLists.txt b/slsDetectorGui/CMakeLists.txt index 680922825..8b7cd1bc2 100755 --- a/slsDetectorGui/CMakeLists.txt +++ b/slsDetectorGui/CMakeLists.txt @@ -5,8 +5,23 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) +# Qt6 when it is there, Qt 5.15 otherwise (RHEL8 has no Qt6 packages). To build +# with Qt5 where both are installed: -DCMAKE_DISABLE_FIND_PACKAGE_Qt6=ON # Concurrent is needed for the acquisition thread in qDrawPlot.cpp -find_package(Qt6 6.2 REQUIRED COMPONENTS Widgets Gui Core Concurrent) +set(SLS_QT_COMPONENTS Widgets Gui Core Concurrent) +if(SLS_USE_TESTS) + list(APPEND SLS_QT_COMPONENTS Test) +endif() +find_package(Qt6 6.2 QUIET COMPONENTS ${SLS_QT_COMPONENTS}) +if(Qt6_FOUND) + set(SLS_QT Qt6) +else() + find_package(Qt5 5.15 REQUIRED COMPONENTS ${SLS_QT_COMPONENTS}) + set(SLS_QT Qt5) +endif() +message(STATUS "slsDetectorGui: using ${SLS_QT} ${${SLS_QT}_VERSION}") +# the gui RPM depends on the same Qt +set(SLS_QT ${SLS_QT} PARENT_SCOPE) find_package(PNG REQUIRED) find_package(ZLIB REQUIRED) @@ -43,9 +58,9 @@ target_link_libraries(slsDetectorPlotting PUBLIC slsProjectOptions slsSupportStatic - Qt6::Widgets - Qt6::Gui - Qt6::Core + ${SLS_QT}::Widgets + ${SLS_QT}::Gui + ${SLS_QT}::Core PRIVATE slsProjectWarnings ) @@ -125,7 +140,7 @@ target_link_libraries(slsDetectorGui PUBLIC slsDetectorPlotting PNG::PNG ZLIB::ZLIB - Qt6::Concurrent + ${SLS_QT}::Concurrent PRIVATE slsProjectWarnings diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h index 28f22d65f..9059eceda 100644 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQtPlotCommon.h @@ -8,10 +8,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -19,6 +21,16 @@ namespace sls { namespace plot { +// Position of a mouse or gesture event in the widget. Qt5 has another name for +// it. Not for wheel events, they have position() in both. +template QPointF eventPos(const Event *e) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return e->position(); +#else + return e->localPos(); +#endif +} + // Palettes offered by the image scale panel. Color / BW1 / BW2 are the // original three and stay first (the b / B / c shortcuts use those indices). // Gain4 is the fixed, muted palette for the 0..3 gain bits and is *not* in the diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp index bded994fa..e5833306a 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt1DPlot.cpp @@ -1453,7 +1453,7 @@ void SlsQt1DPlot::paintEvent(QPaintEvent *event) { // --------------------------------------------------------------------------- void SlsQt1DPlot::mousePressEvent(QMouseEvent *event) { - const QPointF pos = event->position(); + const QPointF pos = sls::plot::eventPos(event); const Geometry g = computeGeometry(); if (zoomAllowed()) { if (event->button() == Qt::LeftButton && @@ -1490,7 +1490,7 @@ void SlsQt1DPlot::mousePressEvent(QMouseEvent *event) { } void SlsQt1DPlot::mouseMoveEvent(QMouseEvent *event) { - const QPointF pos = event->position(); + const QPointF pos = sls::plot::eventPos(event); const Geometry g = computeGeometry(); const bool inside = g.plot.contains(pos.toPoint()); if (inside != m_trackValid || pos != m_trackPos) { diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp index 297a1787b..18a74dd74 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQtFastImage.cpp @@ -632,7 +632,7 @@ void SlsQtFastImage::mousePressEvent(QMouseEvent *e) { if (e->button() != Qt::LeftButton || !m_zoomEnabled || !hasImage()) return; m_panning = true; - m_panStart = e->position(); + m_panStart = plot::eventPos(e); m_panStartArea = visibleArea(); setCursor(Qt::ClosedHandCursor); } @@ -642,12 +642,12 @@ void SlsQtFastImage::mouseMoveEvent(QMouseEvent *e) { return; const Mapping m = mapping(); if (m_panning) { - const QPointF delta = (e->position() - m_panStart) / m.scale; + const QPointF delta = (plot::eventPos(e) - m_panStart) / m.scale; showArea(m_panStartArea.translated(-delta.x(), delta.y())); return; } - updateHover(e->position()); + updateHover(plot::eventPos(e)); } // Finds the pixel under the cursor, for the readout @@ -703,8 +703,8 @@ bool SlsQtFastImage::event(QEvent *e) { const auto *gesture = static_cast(e); if (gesture->gestureType() == Qt::ZoomNativeGesture) { // value() is the change of size since the previous event - zoomAt(gesture->position(), std::max(0.1, 1 + gesture->value())); - updateHover(gesture->position()); + zoomAt(plot::eventPos(gesture), std::max(0.1, 1 + gesture->value())); + updateHover(plot::eventPos(gesture)); return true; } } diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQtScalePanel.cpp b/slsDetectorGui/slsDetectorPlotting/src/SlsQtScalePanel.cpp index a14f3279c..fb6617b46 100644 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQtScalePanel.cpp +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQtScalePanel.cpp @@ -132,7 +132,7 @@ void SlsQtScaleHisto::paintEvent(QPaintEvent *) { void SlsQtScaleHisto::mousePressEvent(QMouseEvent *e) { if (e->button() != Qt::LeftButton) return; - const double x = e->position().x(); + const double x = plot::eventPos(e).x(); const double toLo = std::abs(x - kLoMarker * width()); const double toHi = std::abs(x - kHiMarker * width()); if (std::min(toLo, toHi) > kGrabDistance) @@ -145,7 +145,7 @@ void SlsQtScaleHisto::mousePressEvent(QMouseEvent *e) { void SlsQtScaleHisto::mouseMoveEvent(QMouseEvent *e) { if (!isDragging()) return; - m_dragX = std::clamp(e->position().x(), 0.0, double(width())); + m_dragX = std::clamp(plot::eventPos(e).x(), 0.0, double(width())); update(); } @@ -210,11 +210,11 @@ SlsQtScalePanel::SlsQtScalePanel(SlsQtFastImage *view, QWidget *parent) setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); connect( - m_paletteCombo, &QComboBox::currentIndexChanged, this, + m_paletteCombo, qOverload(&QComboBox::currentIndexChanged), this, [this](int i) { m_view->setPalette(static_cast(i)); }); - connect(m_imageLogCombo, &QComboBox::currentIndexChanged, this, + connect(m_imageLogCombo, qOverload(&QComboBox::currentIndexChanged), this, [this](int i) { m_view->setLogScale(i == 1); }); - connect(m_histoLogCombo, &QComboBox::currentIndexChanged, this, + connect(m_histoLogCombo, qOverload(&QComboBox::currentIndexChanged), this, &SlsQtScalePanel::refresh); connect(m_histo, &SlsQtScaleHisto::rangeChanged, this, [this](double lo, double hi) { diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index aaf6a3ebc..a44beee5f 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -108,6 +108,11 @@ int main(int argc, char **argv) { } } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + // Qt6 always scales with the screen, Qt5 has to be asked + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); +#endif QApplication app(argc, argv); // Use the same (platform independent) widget style everywhere so that the // gui looks the same on linux and macOS. Fusion is built into Qt. diff --git a/slsDetectorGui/tests/CMakeLists.txt b/slsDetectorGui/tests/CMakeLists.txt index 5e322be38..b9ddfa058 100644 --- a/slsDetectorGui/tests/CMakeLists.txt +++ b/slsDetectorGui/tests/CMakeLists.txt @@ -4,14 +4,12 @@ # QtTest suite for the plotting widgets. Needs no display: # QT_QPA_PLATFORM=offscreen bin/plotting_test -find_package(Qt6 6.2 REQUIRED COMPONENTS Test) - add_executable(plotting_test plotting_test.cpp ) target_link_libraries(plotting_test PRIVATE slsDetectorPlotting - Qt6::Test + ${SLS_QT}::Test ) set_target_properties(plotting_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin diff --git a/slsDetectorGui/tests/plotting_test.cpp b/slsDetectorGui/tests/plotting_test.cpp index 27ee4bfe8..06e4b626f 100644 --- a/slsDetectorGui/tests/plotting_test.cpp +++ b/slsDetectorGui/tests/plotting_test.cpp @@ -625,9 +625,14 @@ void PlottingTest::imageTouchpadZoom() { // a pinch magnifies by 1 + value view.resetView(); for (int i = 0; i < 4; i++) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QNativeGestureEvent pinch(Qt::ZoomNativeGesture, QPointingDevice::primaryPointingDevice(), 2, cursor, cursor, cursor, 0.18, QPointF()); +#else + QNativeGestureEvent pinch(Qt::ZoomNativeGesture, cursor, cursor, cursor, + 0.18, 0, 0); +#endif QCoreApplication::sendEvent(&view, &pinch); } QVERIFY(nearRect(view.visibleArea(), wheel));