helloSystem / QtPlugin

Qt platform plugin and style, required for Qt applications to export their menus over D-Bus in the required format
5 stars 4 forks source link

Metrics are wrong on Linux #9

Closed probonopd closed 1 year ago

probonopd commented 3 years ago

On Debian Sid with Qt version 5.15.2, text is not vertically centered.

image

Menu items have too large height. Unlike on FreeBSD, using the exact same fonts.

Why the difference?

image

This is not caused by /etc/xdg/stylesheet.qss because the effect is there even without it. The Qt Unix default theme does not have this issue.

probonopd commented 3 years ago

We need to do something in styleplugin/basestyle.cpp

m.topMargin = 2; // static_cast<int>(fontHeight * MenuItem_VerticalMarginsFontRatio);
m.bottomMargin = 2; // static_cast<int>(fontHeight * MenuItem_VerticalMarginsFontRatio);

This seems to fix the menu item height. Although we might want to hardcode the menu item height to an exact number of pixels instead of calculating it based on the font size; especially if we hardcode the absolute pixel height of the MainWindow that contains the menu. However, keep in mind that for non-global menus different font sizes and hence different menu item heights may be desirable.

For the menu(bar) height we need to change:

    case CT_MenuBarItem: {
        return QSize(size.width() + 10, 22);
    }

This hardcodes the height to 22px. Note that this value should always be kept the same as the height of the MainWindow of the Menu application. Can we make the MainWindow of the Menu application find out the height of the CT_MenuBarItem and just use that?

Text is still not centered.

probonopd commented 3 years ago

Addressing this in https://github.com/helloSystem/QtPlugin/commit/8db9bf21774c8cda42f4a00de36a582a38171e47 and in https://github.com/helloSystem/Menu/commit/6619aed1d7fcef75c263a3324d238b612a4f23bd

probonopd commented 3 years ago

image

Defined by:

  1. QtPlugin CT_MenuBarItem (in helloSystem, we want 22px)
  2. QtPlugin
  3. QtPlugin CT_MenuBarItem (in helloSystem, we want 22px/2)
  4. QtPlugin MenuBar_ItemSpacing (in helloSystem, we want close to 0px)
  5. QtPlugin MenuItemMetrics totalHeight (in helloSystem, we want this depending on the font size; for the main menu we want 22px)
  6. Menu MainWindow height
probonopd commented 3 years ago

Turns out we get different rendering of text in Debian vs. FreeBSD; the reason for this is not clear yet. Using an ugly ifdef for now: https://github.com/helloSystem/QtPlugin/commit/02361cec140e4899b2202d39ab3c6b58dc793fba

probonopd commented 1 year ago

Also noteworthy: The Nimbus Sans in Debian/Ubuntu (fonts-urw-base35) behaves very differently than the Nimbus Sans from https://github.com/ArtifexSoftware/urw-base35-fonts/archive/20200910.zip. When using the latter in both places, I get consistent results. Hence closing.