Results 1 to 12 of 12

Thread: Help with QMenu item stylesheet

  1. #1
    Join Date
    May 2009
    Posts
    5
    Thanks
    1
    Qt products

    Default Help with QMenu item stylesheet

    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:



    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:

    Qt Code:
    1. background-color: white;
    2. }
    3.  
    4. QMenu::item {
    5. padding: 2px 20px 2px 20px;
    6. border: 1px solid transparent; /* reserve space for selection border */
    7. spacing: 20px;
    8. }
    9.  
    10.  
    11. QMenu::item:selected {
    12. border-color: darkblue;
    13. background: rgb(53, 120, 191, 150);
    14. color:white;
    15. }
    16.  
    17. QMenu::separator {
    18. height: 2px;
    19. margin: 2px 5px 2px 4px;
    20. }
    21.  
    22. QMenu::indicator {
    23. width: 20px;
    24. height: 13px;
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Help with QMenu item stylesheet

    Might be prob with padding...
    what if u remove the padding line ?

  3. #3
    Join Date
    May 2009
    Posts
    5
    Thanks
    1
    Qt products

    Default Re: Help with QMenu item stylesheet

    Removing padding makes the menu itself smaller, but the space between the text remains the same for some reason.

  4. #4
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help with QMenu item stylesheet

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Help with QMenu item stylesheet

    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.

  6. #6
    Join Date
    May 2009
    Posts
    5
    Thanks
    1
    Qt products

    Default Re: Help with QMenu item stylesheet

    Quote Originally Posted by Lykurg View Post
    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?

    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.

  7. #7
    Join Date
    May 2009
    Posts
    5
    Thanks
    1
    Qt products

    Default Re: Help with QMenu item stylesheet

    Anyone have an idea on how to fix this?

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help with QMenu item stylesheet

    maybe I missed something, but add min-width in css for QMenu::item.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. The following user says thank you to spirit for this useful post:

    Sufu (9th May 2009)

  10. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Help with QMenu item stylesheet

    Quote Originally Posted by spirit View Post
    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.

  11. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help with QMenu item stylesheet

    Quote Originally Posted by Lykurg View Post
    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
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #11
    Join Date
    May 2009
    Posts
    5
    Thanks
    1
    Qt products

    Thumbs up Re: Help with QMenu item stylesheet

    Quote Originally Posted by spirit View Post
    maybe I missed something, but add min-width in css for QMenu::item.
    Not the most elegant solution but it works! Thanks!

  13. #12
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Help with QMenu item stylesheet

    Quote Originally Posted by Sufu View Post
    Not the most elegant solution but it works! Thanks!
    Have you send a report to Qt? Because this should be fixed...

Similar Threads

  1. Two icons for each item in QMenu?
    By ultr in forum Qt Programming
    Replies: 9
    Last Post: 15th December 2010, 15:13
  2. Replies: 1
    Last Post: 18th March 2009, 04:56
  3. View, Scene, Item and thread??
    By dungsivn in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 19:21
  4. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  5. Replies: 1
    Last Post: 19th April 2007, 22:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.