[PATCH] Fix menu item widths in KStyle-based styles

Robert Knight robertknight at gmail.com
Wed Jan 2 15:43:14 GMT 2008


Hello,

Menu items in the Oxygen style are currently much wider than they
should be.  This is particularly evident in Konsole which uses lots of
long Ctrl+Shift+[Letter] shortcuts.  I looked through the KStyle and
the QMenu code and it seems that the reason for this is that width for
the shortcut text is being allocated twice.

KStyle::sizeFromContents() calculates the width for the action's text
plus shortcut and then adds the style-specific accelerator spacing (
KStyle::MenuItem::AccelSpace widget layout property ).

Meanwhile QMenuPrivate::calcActionRects() iterates over each action in
the menu to be displayed and calculates the maximum item width (using
the current style's sizeFromContents() which includes the shortcut
text width) and also the maximum "tab width" (width of the shortcut
text).  It then adds the maximum tab width to the maximum item width
at the end to get the final width.

I think the error here is in the QMenu code, since I would consider
the shortcut text part of the contents of a menu item and so the style
should have control over the amount of space allocated for it.
However, I also don't think this bug can be fixed within Qt since it
would break existing 3rd-party styles.  Attached is a trivial patch
against KStyle which fixes the problem, although the documentation
needs updates as well to explain the problem.

One question is what to do about the AccelSpace enum value in
kstyle.h.  Removing it would be BIC.

Regards,
Robert.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kdelibs_kdeui_kstyle_fix_menu_item_width.patch
Type: text/x-patch
Size: 676 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080102/d6fda238/attachment.bin>


More information about the kde-core-devel mailing list