diff --git a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp index 166037aa23..53587db4ee 100644 --- a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp @@ -650,7 +650,7 @@ QImage RimMultiPlot::captureSnapshot( int width, int height ) QSize orgViewSize = m_viewer->size(); - image = RimViewWindow::internalCaptureSnapshot( m_viewer->bookWidget(), width, height ); + image = RimViewWindow::internalCaptureSnapshot( m_dockWidget, m_viewer->bookWidget(), width, height ); m_viewer->resize( orgViewSize ); doUpdateLayout(); diff --git a/ApplicationLibCode/ProjectDataModel/RimViewWindow.cpp b/ApplicationLibCode/ProjectDataModel/RimViewWindow.cpp index 975369d6e2..facc1e5e99 100644 --- a/ApplicationLibCode/ProjectDataModel/RimViewWindow.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimViewWindow.cpp @@ -20,24 +20,21 @@ #include "RiaColorTables.h" #include "RiaColorTools.h" -#include "RiaFieldHandleTools.h" #include "RiaGuiApplication.h" #include "RiaPreferencesSystem.h" #include "RicfCommandObject.h" #include "RimDockWindowController.h" -#include "RimProject.h" #include "RiuDockWidgetTools.h" #include "cafPdmUiTreeAttributes.h" -#include "cafPdmUiTreeViewEditor.h" #include "DockManager.h" #include "DockWidget.h" -#include +#include #include #include #include @@ -234,22 +231,33 @@ QImage RimViewWindow::snapshotWindowContent() //-------------------------------------------------------------------------------------------------- QImage RimViewWindow::captureSnapshot( int width, int height ) { - return internalCaptureSnapshot( viewWidget(), width, height ); + return internalCaptureSnapshot( m_dockWidget, viewWidget(), width, height ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QImage RimViewWindow::internalCaptureSnapshot( QWidget* widget, int width, int height ) +QImage RimViewWindow::internalCaptureSnapshot( ads::CDockWidget* dockWidget, QWidget* widget, int width, int height ) { if ( !widget ) return QImage(); + if ( dockWidget && !dockWidget->isCurrentTab() ) + { + // Move the dock widget that is stacked behind others in the same dock area to the top to make sure the snapshot is rendered + dockWidget->setAsCurrentTab(); + QApplication::processEvents(); + } + bool shouldResize = width > 0 && height > 0 && ( widget->width() != width || widget->height() != height ); QSize orgSize = widget->size(); if ( shouldResize ) { widget->setFixedSize( width, height ); + + // setFixedSize() only posts a deferred resize. If the pending resize is delivered from inside QWidget::render() below, a child + // QScrollArea may move its viewport mid-render and crash in Qt's backing-store blit (QWidgetRepaintManager::bltRect). + QApplication::processEvents(); } else { diff --git a/ApplicationLibCode/ProjectDataModel/RimViewWindow.h b/ApplicationLibCode/ProjectDataModel/RimViewWindow.h index 7679c3dfe0..47a1154702 100644 --- a/ApplicationLibCode/ProjectDataModel/RimViewWindow.h +++ b/ApplicationLibCode/ProjectDataModel/RimViewWindow.h @@ -25,8 +25,7 @@ #include "cafPdmField.h" #include "cafPdmObject.h" -#include - +class QImage; class RimDockWindowController; namespace ads @@ -103,7 +102,7 @@ protected: void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; - static QImage internalCaptureSnapshot( QWidget* widget, int width, int height ); + static QImage internalCaptureSnapshot( ads::CDockWidget* dockWidget, QWidget* widget, int width, int height ); private: friend class RimProject;