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

Fix for the font of truncated sidebar items (#5714). #5777

Merged
merged 3 commits into from
Nov 14, 2020

Conversation

DigArtRoks
Copy link
Contributor

For windows platforms, retrieve the system font and set it for the FileBrowserTreeWidget. This makes sure that truncated items will use the font as non-truncated items.

For windows platforms, retrieve the system font and set it for the FileBrowserTreeWidget. This makes sure that truncated items will use the font as non-truncated items.
@DigArtRoks
Copy link
Contributor Author

DigArtRoks commented Nov 10, 2020

It looks like there is a shortcoming/bug in QT. When it truncates the text of an item because the sidebar is made smaller, it uses another font (in particular MS Shell Dlg 2 vs. Segoe UI for non-truncated items on my Win10 box).

The issue is flagged here: https://bugreports.qt.io/browse/QTBUG-29232.
Also the QTableWiget seems to have a similar issue: https://bugreports.qt.io/browse/QTBUG-22572.

Both bugreports do a suggestion to fix it or workaround it.

  • Set font-family in the stylesheet. This works also fine for LMMS, but in the stylesheet there is no font at all defined. Also a font may not be available or not the same as the system font that is used for other QT Widgets. So I rejected this.
  • Retrieve the font that is used by Windows for Non-Client area elements and set it as font for the QApplication. This also works fine for LMMS, but for some reason it changes quite a lot of other text labels in the UI as well.

Taking it further I implemented the second proposal and apply the retrieved font only on the FileBrowserTreeWidget. Resizing the sidebar now looks clean when text items get truncated (at least on my Win10).
I was not sure where to put the function (getWin32SystemFont) to retrieve the system font. Please advice if there is a better location. The fix is only applicable for Windows builds, but I understood from the issue that it is anyway only Windows related.

@Spekular, unfortunately it's adding logic instead of removing logic.

@LmmsBot
Copy link

LmmsBot commented Nov 10, 2020

🤖 Hey, I'm @LmmsBot from github.com/lmms/bot and I made downloads for this pull request, click me to make them magically appear! 🎩

Linux

Windows

macOS

🤖
{"platform_name_to_artifacts": {"Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://10375-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.5%2Bg8cc03c9-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/10375?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "Windows": [{"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://10379-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.5%2Bg8cc03c958-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/10379?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://10377-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.5%2Bg8cc03c958-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/10377?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/miy8htycx4ixkm2a/artifacts/build/lmms-1.3.0-alpha-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/36303461"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/bdhxbhcst6g2i5dy/artifacts/build/lmms-1.3.0-alpha-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/36303461"}], "macOS": [{"artifact": {"title": {"title": "", "platform_name": "macOS"}, "link": {"link": "https://10376-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.5%2Bg8cc03c958-mac10.13.dmg"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/10376?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}]}, "commit_sha": "b3e9da21395bb26f7a437253d652642727ef4c25"}

@Spekular
Copy link
Member

Tested and working for me. I don't see any issues with the code itself but I'd love to hear from someone else, especially regarding this:

I was not sure where to put the function (getWin32SystemFont) to retrieve the system font. Please advice if there is a better location.

As for this:

@Spekular, unfortunately it's adding logic instead of removing logic.

That is a bit unfortunate, but worth it IMO. That being said, I would add a link to the qt bug report and a searchable keyword to the comments. That should make it easier to remove this code when it becomes obsolete. Something like

// Workaround this qt bug, fixed in 5.12.2: https://bugreports.qt.io/browse/QTBUG-29232
// TODO: remove this when all builds use a recent enough version of qt

@superpaik
Copy link
Contributor

superpaik commented Nov 11, 2020

It works perfect. Tested on both 32 and 64bits, on Windows10.
I can't say anything to the code review, sorry.

@DigArtRoks
Copy link
Contributor Author

Thanks!
I added the suggested comments in an additional commit.

@Spekular
Copy link
Member

Merging ~24h from now if there are no objections. Shouldn't be hard to move the font function if it does belong elsewhere :P

@DomClark
Copy link
Member

How about adding the condition QT_VERSION < QT_VERSION_CHECK(5, 12, 2) in addition to LMMS_BUILD_WIN32? Quoting myself from #5598:

Knowing which parts can be removed later is easy - just search the codebase for QT_VERSION. This is something we've already done before, to remove Qt 4 compatibility code.

As for where to put getWin32SystemFont, I think GuiApplication is fine if it could be useful elsewhere, otherwise I would put it in an anonymous namespace in src/gui/FileBrowser.cpp. Since the Qt bug report mentions other cases where the bug can occur, let's keep the function where it is for now in case the bug crops up somewhere else before we update Qt.

@DigArtRoks
Copy link
Contributor Author

Thanks. Good suggestion! I added the check and commited again.

@Spekular
Copy link
Member

Good suggestion indeed, I'll have to remember that for the future. My approving review stands, @DomClark if the newly added check is to your satisfaction I'm still in favor of a merge.

@Spekular Spekular merged commit 4fb6654 into LMMS:master Nov 14, 2020
@Spekular
Copy link
Member

🎉

IanCaio pushed a commit to IanCaio/lmms that referenced this pull request Mar 28, 2021
* Fix for the font of truncated sidebar items (LMMS#5714).

For windows platforms, retrieve the system font and set it for the FileBrowserTreeWidget. This makes sure that truncated items will use the font as non-truncated items.

* Add TODO to remove the fix when all builds use a recent enough version of qt.

* Add check on QT version and conditionally include the fix.
sdasda7777 pushed a commit to sdasda7777/lmms that referenced this pull request Jun 28, 2022
* Fix for the font of truncated sidebar items (LMMS#5714).

For windows platforms, retrieve the system font and set it for the FileBrowserTreeWidget. This makes sure that truncated items will use the font as non-truncated items.

* Add TODO to remove the fix when all builds use a recent enough version of qt.

* Add check on QT version and conditionally include the fix.
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

Successfully merging this pull request may close these issues.

5 participants