feat(qt6): QOpenGLWidget-based plot widget and demo

This commit is contained in:
Martino Ferrari committed 2026-09-28 01:17:45 +02:00
1 parent dc0a977c86
commit 1ee2dd9c3d
7 files changed
+1113 -2

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
# The Qt6 adapter: a QOpenGLWidget that renders a plot into its own framebuffer
# and drives it from Qt's events. It is the third host, and the first whose
# toolkit already owns a GL widget -- so the interesting parts are the surface
# format the application must have set before the widget exists (documented on
# the class) and the device-pixel-ratio mapping between Qt's logical coordinates
# and the framebuffer pixels the library speaks.
#
# Unlike the GLFW and ImGui adapters this one is not fetched: Qt is a system SDK,
# and a project that enables this target is asking for the installed one.
find_package(Qt6 QUIET COMPONENTS Core Gui Widgets OpenGLWidgets)
if(NOT Qt6_FOUND)
message(FATAL_ERROR
"plot: PLOT_BUILD_QT6 is ON but Qt6 was not found (need the Core, Gui, Widgets"
" and OpenGLWidgets components). Install Qt6 -- on Arch, qt6-base -- or"
" configure with -DPLOT_BUILD_QT6=OFF, or point CMAKE_PREFIX_PATH at the Qt6"
" installation.")
endif()
add_library(plot_qt6 STATIC qt_plot_widget.cpp qt_plot_widget.hpp)
add_library(plot::qt6 ALIAS plot_qt6)
# The public include root is `adapters/`, so the header is reached as
# <qt6/qt_plot_widget.hpp> -- the toolkit's name first, like every other adapter's.
target_include_directories(plot_qt6 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
# Qt is PUBLIC, unlike GLFW and ImGui: the widget's header derives from
# QOpenGLWidget, so a consumer needs Qt's headers and libraries to use it at all.
target_link_libraries(plot_qt6 PUBLIC
plot::core
Qt6::Core
Qt6::Gui
Qt6::Widgets
Qt6::OpenGLWidgets)
# The widget declares Q_OBJECT, so its header has to go through moc. The property
# is set on this target rather than globally: no other target in the project has a
# Qt class in it, and AUTOMOC scans every source of a target it is set on.
set_target_properties(plot_qt6 PROPERTIES AUTOMOC ON)
plot_apply_warnings(plot_qt6)