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

High DPI scaling issues with Qt::AA_EnableHighDpiScaling (macbook pro retina ubuntu 16.04) #1262

Closed
rlober opened this issue Jun 19, 2018 · 4 comments

Comments

@rlober
Copy link
Contributor

rlober commented Jun 19, 2018

tl;dr
I am raising this issue as a follow up to #1077 which was partially fixed in #1078. Qt::AA_EnableHighDpiScaling causes RenderWidget resize event to be 1/2 the proper size. Proposed fix in #1263.

Setup:

  • macbook pro late 2011
  • retina display
  • ubuntu 16.04
  • branch: kinetic-devel
  • rviz at commit: 87742e4
  • rviz version 1.12.16
  • compiled against Qt version 5.11.0
  • compiled against OGRE version 1.9.0 (Ghadamon)

Problem:
Since Qt 5.6 (see here), high DPI scaling can be handled automatically by setting the application attribute Qt::AA_EnableHighDpiScaling in the main.cpp of a Qt application.

// Enable support for high DPI screens 
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

This makes gui design more homogeneous across screens (at least where pixel coordinates are concerned).

Unfortunately when I enable this attribute and am using librviz, the RenderWidget only fills 1/4 of the RenderPanel:
image

The rest of the space is filled with whatever was behind the RenderPanel upon a resize event.

When I do not set the AA_EnableHighDpiScaling attribute the RenderWidget displays properly, but the rest of the gui (not shown) is far too small:
image

The image above is scaled here but on my screen it is 2x smaller than it should be. This is because AA_EnableHighDpiScaling is not set.

Resolution:

I say this problem was partially fixed in #1078 because the AA_EnableHighDpiScaling is never used in rviz and the RenderWidget displays as expected.

I traced the problem to the resizeEvent() handler in RenderWidget:

void RenderWidget::resizeEvent(QResizeEvent *e)
{
  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.
    render_window_->resize( width() + (width() % 2), height() );
    render_window_->windowMovedOrResized();
  }
}

When using AA_EnableHighDpiScaling, the functions width() and height() return the widget width and height with respect to a virtual pixel coordinate system and not the real pixel coordinate system. The Ogre::RenderWindow on the other hand is expressed in the real pixel coordiante system (I think...) and therefore only renders at 1/devicePixelRatio().

I have proposed a fix in #1263 which simply multiplies the width and height by the pixel ratio:

render_window_->resize( width()*pixel_ratio_ + (width()*pixel_ratio_ % 2), height()*pixel_ratio_ );

This results in a properly scaled RenderWidget:
image

When not using AA_EnableHighDpiScaling, the widget fills the panel but it the whole gui is half the size, which is the expected behavior on high DPI screens.

@mgrrx
Copy link

mgrrx commented Jul 23, 2018

I tried the proposed fix on my Mac and it seems to work. Not sure if it is related to the issue described here when I try to do e.g. a Pose Estimate it only works in the upper right corner of the rendering area.

@tompe17
Copy link

tompe17 commented Sep 24, 2018

I see this issue on Ubuntu 18.04 and melodic. Did not have the issue on 16.04 and kinetic.

@ahoarau
Copy link
Contributor

ahoarau commented Nov 29, 2018

Same issue with a Dell XPS 4k (16.04 / kinetic). #1263 fixes it.

@rhaschke
Copy link
Contributor

Fixed via #1263.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants