diff --git a/src/rviz/ogre_helpers/render_widget.cpp b/src/rviz/ogre_helpers/render_widget.cpp index 081caf9b38..94eb2b19bd 100644 --- a/src/rviz/ogre_helpers/render_widget.cpp +++ b/src/rviz/ogre_helpers/render_widget.cpp @@ -80,11 +80,14 @@ RenderWidget::RenderWidget( RenderSystem* render_system, QWidget *parent ) QApplication::flush(); #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) QApplication::syncX(); + pixel_ratio_ = 1.0; #else QApplication::sync(); + QWindow* window = windowHandle(); + pixel_ratio_ = window ? window->devicePixelRatio() : 1.0; #endif - render_window_ = render_system_->makeRenderWindow(win_id, width(), height(), pixelRatio()); + render_window_ = render_system_->makeRenderWindow(win_id, width(), height(), pixel_ratio_); } RenderWidget::~RenderWidget() @@ -121,25 +124,13 @@ void RenderWidget::resizeEvent(QResizeEvent *) { if( render_window_ ) { - // render_window_->writeContentsToFile() (used in - // VisualizationFrame::onSaveImage()) does not work right for - // window with an odd width, so here I just always force it to be - // even. - const qreal ratio = pixelRatio(); - const int w = width() * ratio; - render_window_->resize(w + (w % 2), height() * ratio); + /* render_window_->writeContentsToFile() (used in VisualizationFrame::onSaveImage()) + * does not work right for window with an odd width. + * So here we just always force it to be even. */ + const int w = width() * pixel_ratio_; + render_window_->resize(w + (w % 2), height() * pixel_ratio_); render_window_->windowMovedOrResized(); } } -qreal RenderWidget::pixelRatio() const -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - return 1.0; -#else - QWindow* window = windowHandle(); - return window ? window->devicePixelRatio() : 1.0; -#endif -} - } // end namespace rviz diff --git a/src/rviz/ogre_helpers/render_widget.h b/src/rviz/ogre_helpers/render_widget.h index 00143135c9..d8d05819f7 100644 --- a/src/rviz/ogre_helpers/render_widget.h +++ b/src/rviz/ogre_helpers/render_widget.h @@ -53,7 +53,6 @@ class RenderWidget: public QWidget virtual void moveEvent(QMoveEvent *e); virtual void paintEvent(QPaintEvent *e); virtual void resizeEvent(QResizeEvent *e); - qreal pixelRatio() const; #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QPaintEngine *paintEngine() const { return 0; } @@ -61,7 +60,7 @@ class RenderWidget: public QWidget RenderSystem* render_system_; Ogre::RenderWindow* render_window_; - + qreal pixel_ratio_; QFrame* renderFrame; };