Merge pull request #21194 from whalenpt:qt_opengl_build_fix

pull/21238/head
Alexander Alekhin 3 years ago
commit 7ba56a4b88
  1. 7
      cmake/OpenCVFindLibsGUI.cmake
  2. 5
      modules/highgui/CMakeLists.txt
  3. 23
      modules/highgui/src/window_QT.cpp
  4. 18
      modules/highgui/src/window_QT.h

@ -47,6 +47,13 @@ if(WITH_QT)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGL QUIET) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGL QUIET)
if(Qt${QT_VERSION_MAJOR}OpenGL_FOUND) if(Qt${QT_VERSION_MAJOR}OpenGL_FOUND)
set(QT_QTOPENGL_FOUND ON) # HAVE_QT_OPENGL is defined below set(QT_QTOPENGL_FOUND ON) # HAVE_QT_OPENGL is defined below
if(QT_VERSION_MAJOR GREATER 5) # QGL -> QOpenGL
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGLWidgets QUIET)
if(NOT Qt${QT_VERSION_MAJOR}OpenGLWidgets_FOUND)
message(STATUS "Qt OpenGLWidgets component not found: turning off Qt OpenGL functionality")
set(QT_QTOPENGL_FOUND FALSE)
endif()
endif()
endif() endif()
endif() endif()
endif() endif()

@ -60,6 +60,7 @@ if(HAVE_QT)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
if(QT_VERSION_MAJOR EQUAL 6) if(QT_VERSION_MAJOR EQUAL 6)
add_definitions(-DHAVE_QT6) # QGLWidget deprecated for QT6, use this preprocessor to adjust window_QT.[h,cpp]
QT6_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc) QT6_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc)
QT6_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h) QT6_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h)
elseif(QT_VERSION_MAJOR EQUAL 5) elseif(QT_VERSION_MAJOR EQUAL 5)
@ -78,6 +79,10 @@ if(HAVE_QT)
set(qt_deps Core Gui Widgets Test Concurrent) set(qt_deps Core Gui Widgets Test Concurrent)
if(HAVE_QT_OPENGL) if(HAVE_QT_OPENGL)
add_definitions(-DHAVE_QT_OPENGL) add_definitions(-DHAVE_QT_OPENGL)
# QOpenGLWidget requires Qt6 package component OpenGLWidgets
if(QT_VERSION_MAJOR GREATER 5)
list(APPEND qt_deps OpenGLWidgets)
endif()
list(APPEND qt_deps OpenGL) list(APPEND qt_deps OpenGL)
endif() endif()

@ -3227,7 +3227,9 @@ void DefaultViewPort::setSize(QSize /*size_*/)
#ifdef HAVE_QT_OPENGL #ifdef HAVE_QT_OPENGL
OpenGlViewPort::OpenGlViewPort(QWidget* _parent) : QGLWidget(_parent), OCVViewPort(), size(-1, -1)
// QOpenGLWidget vs QGLWidget info: https://www.qt.io/blog/2014/09/10/qt-weekly-19-qopenglwidget
OpenGlViewPort::OpenGlViewPort(QWidget* _parent) : OpenCVQtWidgetBase(_parent), OCVViewPort(), size(-1, -1)
{ {
glDrawCallback = 0; glDrawCallback = 0;
glDrawData = 0; glDrawData = 0;
@ -3281,7 +3283,11 @@ void OpenGlViewPort::makeCurrentOpenGlContext()
void OpenGlViewPort::updateGl() void OpenGlViewPort::updateGl()
{ {
#ifdef HAVE_QT6
QOpenGLWidget::update();
#else
QGLWidget::updateGL(); QGLWidget::updateGL();
#endif
} }
void OpenGlViewPort::initializeGL() void OpenGlViewPort::initializeGL()
@ -3308,31 +3314,31 @@ void OpenGlViewPort::paintGL()
void OpenGlViewPort::wheelEvent(QWheelEvent* evnt) void OpenGlViewPort::wheelEvent(QWheelEvent* evnt)
{ {
icvmouseEvent((QMouseEvent *)evnt, mouse_wheel); icvmouseEvent((QMouseEvent *)evnt, mouse_wheel);
QGLWidget::wheelEvent(evnt); OpenCVQtWidgetBase::wheelEvent(evnt);
} }
void OpenGlViewPort::mousePressEvent(QMouseEvent* evnt) void OpenGlViewPort::mousePressEvent(QMouseEvent* evnt)
{ {
icvmouseEvent(evnt, mouse_down); icvmouseEvent(evnt, mouse_down);
QGLWidget::mousePressEvent(evnt); OpenCVQtWidgetBase::mousePressEvent(evnt);
} }
void OpenGlViewPort::mouseReleaseEvent(QMouseEvent* evnt) void OpenGlViewPort::mouseReleaseEvent(QMouseEvent* evnt)
{ {
icvmouseEvent(evnt, mouse_up); icvmouseEvent(evnt, mouse_up);
QGLWidget::mouseReleaseEvent(evnt); OpenCVQtWidgetBase::mouseReleaseEvent(evnt);
} }
void OpenGlViewPort::mouseDoubleClickEvent(QMouseEvent* evnt) void OpenGlViewPort::mouseDoubleClickEvent(QMouseEvent* evnt)
{ {
icvmouseEvent(evnt, mouse_dbclick); icvmouseEvent(evnt, mouse_dbclick);
QGLWidget::mouseDoubleClickEvent(evnt); OpenCVQtWidgetBase::mouseDoubleClickEvent(evnt);
} }
void OpenGlViewPort::mouseMoveEvent(QMouseEvent* evnt) void OpenGlViewPort::mouseMoveEvent(QMouseEvent* evnt)
{ {
icvmouseEvent(evnt, mouse_move); icvmouseEvent(evnt, mouse_move);
QGLWidget::mouseMoveEvent(evnt); OpenCVQtWidgetBase::mouseMoveEvent(evnt);
} }
@ -3340,8 +3346,7 @@ QSize OpenGlViewPort::sizeHint() const
{ {
if (size.width() > 0 && size.height() > 0) if (size.width() > 0 && size.height() > 0)
return size; return size;
return OpenCVQtWidgetBase::sizeHint();
return QGLWidget::sizeHint();
} }
void OpenGlViewPort::setSize(QSize size_) void OpenGlViewPort::setSize(QSize size_)
@ -3350,6 +3355,6 @@ void OpenGlViewPort::setSize(QSize size_)
updateGeometry(); updateGeometry();
} }
#endif #endif //HAVE_QT_OPENGL
#endif // HAVE_QT #endif // HAVE_QT

@ -48,7 +48,14 @@
#if defined( HAVE_QT_OPENGL ) #if defined( HAVE_QT_OPENGL )
#include <QtOpenGL> #include <QtOpenGL>
#include <QGLWidget>
// QGLWidget deprecated and no longer functions with Qt6, use QOpenGLWidget instead
#ifdef HAVE_QT6
#include <QOpenGLWidget>
#else
#include <QGLWidget>
#endif
#endif #endif
#include <QAbstractEventDispatcher> #include <QAbstractEventDispatcher>
@ -431,7 +438,14 @@ protected:
#ifdef HAVE_QT_OPENGL #ifdef HAVE_QT_OPENGL
class OpenGlViewPort : public QGLWidget, public OCVViewPort // Use QOpenGLWidget for Qt6 (QGLWidget is deprecated)
#ifdef HAVE_QT6
typedef QOpenGLWidget OpenCVQtWidgetBase;
#else
typedef QGLWidget OpenCVQtWidgetBase;
#endif
class OpenGlViewPort : public OpenCVQtWidgetBase, public OCVViewPort
{ {
public: public:
explicit OpenGlViewPort(QWidget* parent); explicit OpenGlViewPort(QWidget* parent);

Loading…
Cancel
Save