Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize RenderWidget properly when using different DPI scaling. #1263

Merged
merged 7 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/rviz/ogre_helpers/render_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace rviz
RenderWidget::RenderWidget( RenderSystem* render_system, QWidget *parent )
: QWidget( parent )
, render_system_( render_system )
, render_window_( nullptr )
, render_window_( 0 )
{
setAttribute(Qt::WA_OpaquePaintEvent,true);
setAttribute(Qt::WA_PaintOnScreen,true);
Expand Down Expand Up @@ -78,15 +78,13 @@ RenderWidget::RenderWidget( RenderSystem* render_system, QWidget *parent )
rviz::RenderSystem::WindowIDType win_id = this->winId();
#endif
QApplication::flush();

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QApplication::syncX();
double pixel_ratio = 1.0;
rlober marked this conversation as resolved.
Show resolved Hide resolved
#else
QWindow* window = windowHandle();
double pixel_ratio = window ? window->devicePixelRatio() : 1.0;
QApplication::sync();
#endif
render_window_ = render_system_->makeRenderWindow(win_id, width(), height(), pixel_ratio);

render_window_ = render_system_->makeRenderWindow(win_id, width(), height(), pixelRatio());
}

RenderWidget::~RenderWidget()
Expand Down Expand Up @@ -127,9 +125,21 @@ void RenderWidget::resizeEvent(QResizeEvent *)
// VisualizationFrame::onSaveImage()) does not work right for
// window with an odd width, so here I just always force it to be
// even.
render_window_->resize( width() + (width() % 2), height() );
const qreal ratio = pixelRatio();
const int w = width() * ratio;
render_window_->resize(w + (w % 2), height() * 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
1 change: 1 addition & 0 deletions src/rviz/ogre_helpers/render_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ 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; }
Expand Down