diff --git a/avogadro/mainwindow.cpp b/avogadro/mainwindow.cpp index 1e417800..4999b3ba 100644 --- a/avogadro/mainwindow.cpp +++ b/avogadro/mainwindow.cpp @@ -368,6 +368,7 @@ void MainWindow::setupInterface() m_multiViewWidget->setFactory(m_viewFactory); setCentralWidget(m_multiViewWidget); auto* glWidget = new GLWidget(this); + m_viewFactory->setGLWidget(glWidget); // set the background color (alpha channel default should be opaque) auto color = diff --git a/avogadro/viewfactory.cpp b/avogadro/viewfactory.cpp index 86e4644a..05c77d21 100644 --- a/avogadro/viewfactory.cpp +++ b/avogadro/viewfactory.cpp @@ -12,13 +12,9 @@ namespace Avogadro { -ViewFactory::ViewFactory() -{ -} +ViewFactory::ViewFactory() {} -ViewFactory::~ViewFactory() -{ -} +ViewFactory::~ViewFactory() {} QStringList ViewFactory::views() const { @@ -32,8 +28,17 @@ QStringList ViewFactory::views() const QWidget* ViewFactory::createView(const QString& view) { - if (view == QObject::tr("3D View")) - return new QtOpenGL::GLWidget; + if (view == QObject::tr("3D View")) { + // get the background color, etc. + if (m_glWidget != nullptr) { + auto newWidget = new QtOpenGL::GLWidget(m_glWidget); + // set the background color, etc. + auto bgColor = m_glWidget->renderer().scene().backgroundColor(); + newWidget->renderer().scene().setBackgroundColor(bgColor); + return newWidget; + } else + return new QtOpenGL::GLWidget; + } #ifdef AVO_USE_VTK else if (view == QObject::tr("VTK")) return new VTK::vtkGLWidget; diff --git a/avogadro/viewfactory.h b/avogadro/viewfactory.h index 6313256a..a865b8d3 100644 --- a/avogadro/viewfactory.h +++ b/avogadro/viewfactory.h @@ -7,6 +7,10 @@ #define AVOGADRO_VIEWFACTORY_H #include +#include +#ifdef AVO_USE_VTK +#include +#endif namespace Avogadro { @@ -18,6 +22,10 @@ class ViewFactory : public QtGui::ViewFactory QStringList views() const; QWidget* createView(const QString& view); + void setGLWidget(QtOpenGL::GLWidget* glWidget) { m_glWidget = glWidget; } + +protected: + QtOpenGL::GLWidget* m_glWidget = nullptr; }; } // End namespace Avogadro