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

Qt auto scale factor for HiDPI displays #291

Merged
merged 2 commits into from
Aug 20, 2020
Merged

Qt auto scale factor for HiDPI displays #291

merged 2 commits into from
Aug 20, 2020

Conversation

mabelzhang
Copy link
Contributor

@mabelzhang mabelzhang commented Aug 13, 2020

On HiDPI displays, Ignition menus, fonts, and buttons don't appear correctly.
I don't have a non-HiDPI display to test whether this change messes it up for non-HiDPI displays. Can someone test this?

This PR is the equivalent of setting this on the command line:

export QT_AUTO_SCREEN_SCALE_FACTOR=1

I'm putting this line in ign-gazebo as opposed to ign-gui, because this environment variable needs to be set before ignition::gui::Application is called. I tried setting it in Application() constructor in ign-gui, and that did not have an effect.

Test simply with

ign gazebo

What I did test was whether this flag needs a guard, i.e. getting the value before setting it, then restoring it afterwards. It seems a guard is not needed, because after I terminate ign gazebo, then I launch another app in the same terminal that usually doesn't do auto-scale adjustment, and it still doesn't. So seems the flag is not propagated beyond program termination.

If this gets merged, then I can also add the same line before every Application() call in ign-gui entry point https://github.com/ignitionrobotics/ign-gui/blob/master/src/ign.cc It seems to work there from brief testing.

Before the fix

For example, on such a display with Gnome auto-scaling set to 200%, Ignition menu font sizes are inconsistent. Compare the font sizes of "Show/Hide Grid" and "Cell Count", which are the same size on non-HiDPI displays.
The mouse cursor takes on the wrong shape on the run button, making it difficult to unpause physics:
Screenshot from 2020-08-12 22-53-42_beforeFix

When a second panel is added, the cursor is always in double-arrow for the entire length of the panel title bar, which makes closing the second panel impossible:
Screenshot from 2020-08-12 22-54-56_beforeFix

After the fix

Font sizes are consistent, cursor size and behavior are correct:

Screenshot from 2020-08-12 23-00-37

Signed-off-by: Mabel Zhang [email protected]

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never had DPI issues with my Ignition setup, and adding this environment doesn't seem to be changing anything. So if it fixes other setups, I think it's good to add it in!

src/gui/Gui.cc Outdated
@@ -53,6 +53,9 @@ std::unique_ptr<ignition::gui::Application> createGui(
ignmsg << "Ignition Gazebo GUI v" << IGNITION_GAZEBO_VERSION_FULL
<< std::endl;

// Set auto scaling factor for HiDPI displays
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about checking to see if the env variable exists and only set the the variable if it does not? This allows users to override it if needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 04488ee
Tested with:

$ ign gazebo

in which case the window auto scales, and

$ QT_AUTO_SCREEN_SCALE_FACTOR=0 ign gazebo

in which case the window does not auto scale, and

$ QT_AUTO_SCREEN_SCALE_FACTOR=2 ign gazebo

in which case the window auto scales, and

$ QT_AUTO_SCREEN_SCALE_FACTOR=-1 ign gazebo

in which case the window does not auto scale.

@chapulina chapulina merged commit 1bc1f2d into master Aug 20, 2020
@chapulina chapulina deleted the HiDPI_scaling branch August 20, 2020 16:40
chapulina pushed a commit that referenced this pull request Mar 9, 2021
chapulina pushed a commit that referenced this pull request Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔮 dome Ignition Dome
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants