QMenu items checkable/not-checkable not text aligned?
-
As expected - add a transparent QIcon to one of your menu actions and all is fine. Once I tried to fix it but got a lot of other regressions so I had to revert it. And I'm currently not interested in trying it again - sorry. But I think the workaround should be fine for you.
The problem is that the padding defines the padding of the content rect which includes the decoration and checkbox so we can't 'misuse' this. And when drawing a single element one does not know that other elements have a checkbox so adding an offset there also does not work. Maybe QStyleOptionMenuItem.maxIconWidth should also be initialized with a proper value when only checkable and non-checkable (but no icon) menu items are available... But only for Qt6 I would guess. -
@Christian-Ehrlicher OK. I will note that as the mandated work-around. Thank you for your time.
I heard you teasing Qt6 in praise. Will it improve a lot of shortcomings of Qt? :)
-
@quiret said in QMenu items checkable/not-checkable not text aligned?:
Will it improve a lot of shortcomings of Qt?
Hard to tell - a lot of internal cleanup but not much new on the widgets front. Can't say anything to QML though.
-
I think I found a simple solution but don't know why I did not saw this during my fixes in 5.12.x... do you compile Qt by your own?
-
@Christian-Ehrlicher Yes. Why?
-
@quiret Then please try this fix:
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 72f7ad7455..dd31d67728 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3774,6 +3774,12 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q } textRectOffset = std::max(textRectOffset, cmRect.width()); } + // make sure all items are aligned, no matter if they have an icon, checkbox or nothing + if (m->menuHasCheckableItems) { + QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); + const QRect cmRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); + textRectOffset = std::max(textRectOffset, cmRect.width()); + } QRect textRect = subRule.contentsRect(opt->rect); textRect.setLeft(textRect.left() + textRectOffset);
/edit: updated the patch a little bit to make sure all items are aligned, no matter if they have an icon, checkbox or nothing. Then the alignment should also work when there is an icon and a checkbox entry and the checkbox is larger than the icon.
-
@Christian-Ehrlicher Sorry about the delay. My external HDD was acting up, but I have GOOD NEWS!
This looks dang right. Thank you very much for your help! Do you think this patch can make it into Qt?
-
@quiret said in QMenu items checkable/not-checkable not text aligned?:
Do you think this patch can make it into Qt?
I think yes. Need some more tests to not screw up other stuff - sadly the css styling is very fragile. But I think we don't get it into 5.x because there will be no opensource version of 5.x anymore for the next 12 months afaiu.
-
@Christian-Ehrlicher Oh! Now I understand why you made me go through this tiresome process of compiling Qt from source! That's fine, it takes ages to compile Qt. I really wanted to give you valuable feedback too. But if there is no more update to the git tracker in terms of versioning then I could have been left in the dust. I can assure you that users of my tool will be grateful for your contribution!
I realize the Qt team has two concepts: git tracker and website releases. With "no opensource version of 5.x" do you mean no further branching on the git tracker?
-
@quiret said in QMenu items checkable/not-checkable not text aligned?:
With "no opensource version of 5.x" do you mean no further branching on the git tracker?
I don't know exactly how TQtC will handle it. They said they will the delay the open source version as long as possible (which is a max. of 1 year according the KDE Free Qt Foundation). How they will hide the releases is unknown and there was no real communication from TQtC how they will handle it. Therefore I decided by myself to not port anything back to Qt5 (or Qt6.x-1) because I as a user of the opensource version don't have any advantage out of it.
-