Stellarium HiDPI/4K/UHD Display Scaling in Ubuntu/Linux
Stellarium is an awesome cross-platform desktop astronomy software. However, this is not a review of Stellarium and its awesomeness, but a short post on how to fix Stellarium on HiDPI screens in Ubuntu.
Stellarium can be installed from the package manager:
sudo apt install stellarium
It is also available as a flatpak (which is my preferred way of installing it).
When Stellarium is used on a HiDPI screen (e.g. Dell XPS 15), the fonts look so tiny that it is almost unusable. Scaling the Gnome desktop doesn’t fix the problem. But there is a relatively easy fix (which was hard to find, for some reason). There is an environment variable that can be set to fix this problem. To try it out, launch Stellarium after setting this environment variable:
Since Gnome supports setting environment variables in application shortcuts, it is easy to fix this problem so that whenever Stellarium is launched, it scales correctly to HiDPI displays. First, locate the .desktop file used to launch Stellarium. For me, the flatpak creates the file here:
Open the file in your favorite text editor, and append the environment variable to each Exec line in the file. For example, this line:
Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=stellarium org.stellarium.Stellarium
Exec=env QT_DEVICE_PIXEL_RATIO=2 /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=stellarium org.stellarium.Stellarium
Please note that there are multiple Exec lines in the file — make sure to change all of them. Once the changes are made, save the file, and launch Stellarium again (may require logging out of Gnome and logging back in). It will launch with proper scaling.
Hope this helps. :)