From 3448d86fc598bde856defc4f5ce3597cbbb3e8e8 2015-10-06 07:43:12 From: Miikka Heikkinen Date: 2015-10-06 07:43:12 Subject: [PATCH] Change the opengl widget to be child of the first view of the scene Scene itself doesn't necessarily have a parent, so the old way didn't always find a parent for opengl widget. Change-Id: I60053b94a5979f4142cc3f720f48e38cc7c8d440 Reviewed-by: Titta Heikkala --- diff --git a/src/charts/chartpresenter.cpp b/src/charts/chartpresenter.cpp index e2c0f79..ce7f149 100644 --- a/src/charts/chartpresenter.cpp +++ b/src/charts/chartpresenter.cpp @@ -551,17 +551,15 @@ void ChartPresenter::ensureGLWidget() // GLWidget pointer is wrapped in QPointer as its parent is not in our control, and therefore // can potentially get deleted unexpectedly. if (m_glWidget.isNull() && m_glUseWidget && m_chart->scene()) { - QObject *parent = m_chart->scene()->parent(); - while (parent) { - QWidget *parentWidget = qobject_cast(parent); - if (parentWidget) { - m_glWidget = new GLWidget(m_chart->d_ptr->m_dataset->glXYSeriesDataManager(), - parentWidget); - m_glWidget->setGeometry(m_rect.toRect()); - m_glWidget->show(); - break; - } - parent = parent->parent(); + // Find the view of the scene. If the scene has multiple views, only the first view is + // chosen. + QList views = m_chart->scene()->views(); + if (views.size()) { + QGraphicsView *firstView = views.at(0); + m_glWidget = new GLWidget(m_chart->d_ptr->m_dataset->glXYSeriesDataManager(), + firstView); + m_glWidget->setGeometry(m_rect.toRect()); + m_glWidget->show(); } } #endif