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 5 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
11 changes: 6 additions & 5 deletions src/rviz/ogre_helpers/render_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace rviz
RenderWidget::RenderWidget( RenderSystem* render_system, QWidget *parent )
: QWidget( parent )
, render_system_( render_system )
, render_window_( nullptr )
, render_window_( 0 )
, pixel_ratio_(1.0)
{
setAttribute(Qt::WA_OpaquePaintEvent,true);
setAttribute(Qt::WA_PaintOnScreen,true);
Expand Down Expand Up @@ -81,12 +82,12 @@ RenderWidget::RenderWidget( RenderSystem* render_system, QWidget *parent )

#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
pixel_ratio_ = 1.0;
#else
QWindow* window = windowHandle();
double pixel_ratio = window ? window->devicePixelRatio() : 1.0;
pixel_ratio_ = window ? window->devicePixelRatio() : 1.0;
#endif
render_window_ = render_system_->makeRenderWindow(win_id, width(), height(), pixel_ratio);
render_window_ = render_system_->makeRenderWindow(win_id, width(), height(), pixel_ratio_);
}

RenderWidget::~RenderWidget()
Expand Down Expand Up @@ -127,7 +128,7 @@ 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() );
render_window_->resize( width()*pixel_ratio_ + (static_cast<int>(width()*pixel_ratio_) % 2), height()*pixel_ratio_ );
render_window_->windowMovedOrResized();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/rviz/ogre_helpers/render_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class RenderWidget: public QWidget
Ogre::RenderWindow* render_window_;

QFrame* renderFrame;

double pixel_ratio_;
};

} // end namespace rviz
Expand Down