PDA

View Full Version : Help with QMenu item stylesheet



Sufu
2nd May 2009, 22:49
I can't figure this out, if I apply a stylesheet to QMenu, the spacing between the menu text, and the hotkey text does not expand to adjust for the text length, but if I use the default system menu, it works as expected.

Picture of my problem:

http://img60.imageshack.us/img60/9466/qmenu.jpg (http://img60.imageshack.us/my.php?image=qmenu.jpg)

You can see above that there is not enough space between the text, and it does not seem to expand at all. Any help would be appreciated!

CSS Code:



QMenu {
background-color: white;
}

QMenu::item {
padding: 2px 20px 2px 20px;
border: 1px solid transparent; /* reserve space for selection border */
spacing: 20px;
}


QMenu::item:selected {
border-color: darkblue;
background: rgb(53, 120, 191, 150);
color:white;
}

QMenu::separator {
height: 2px;
margin: 2px 5px 2px 4px;
}

QMenu::indicator {
width: 20px;
height: 13px;
}

aamer4yu
3rd May 2009, 11:54
Might be prob with padding...
what if u remove the padding line ?

Sufu
3rd May 2009, 15:40
Removing padding makes the menu itself smaller, but the space between the text remains the same for some reason.

Boron
3rd May 2009, 16:22
So if the menu looks good without you stylesheet I would incrementally add the styles.
Starting only with the white background for QMenu. Compile and check.
The add a border for QMenu::item. Compile and check again.
And so on...

It takes some time to find the error.

Lykurg
3rd May 2009, 16:24
Causes by the border attribute. Seems to be a bug. So check the task tracker and if no report can be found, minimize your style sheet and sing up an bag report.

Sufu
3rd May 2009, 19:02
Causes by the border attribute. Seems to be a bug. So check the task tracker and if no report can be found, minimize your style sheet and sing up an bag report.

I minimized my stylesheet, and it seems that if I remove QMenu::item from my stylesheet, then I get the correct space between the item text and shortcut text, but I loose the padding on the sides and that means things like checkmarks on the menu end up inside the text (ugly solution.)

If I add QMenu::item, and omit padding, then the whole menu shrinks down, and I also loose the space between the text. If I add padding, it looks ok but I still do not get the normal space between the text in the menu no matter what I try.

I guess this is either some sort of bug, or I am missing something in QMenu::item? :confused:

Also, the border attribute by itself has no effect on the spacing between the text, since I can remove it and still have the same problem.

Sufu
6th May 2009, 22:03
Anyone have an idea on how to fix this?

spirit
7th May 2009, 06:09
maybe I missed something, but add min-width in css for QMenu::item.

Lykurg
7th May 2009, 10:34
add min-width in css for QMenu::item
That is not really satisfying and not very independent if you don't know the entries and the font size of the menu.
The strange behavior is that setting (only) a css border attribute in QMenu::item has effect on the size hint what should not be.

spirit
7th May 2009, 10:35
That is not really satisfying and not very independent if you don't know the entries and the font size of the menu.
The strange behavior is that setting (only) a css border attribute in QMenu::item has effect on the size hint what should not be.

but it works :)

Sufu
9th May 2009, 01:01
maybe I missed something, but add min-width in css for QMenu::item.

Not the most elegant solution but it works! Thanks!

Lykurg
9th May 2009, 06:58
Not the most elegant solution but it works! Thanks!

Have you send a report to Qt? Because this should be fixed...