Results 1 to 10 of 10

Thread: QMenu round corners

  1. #1
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default QMenu round corners

    Hi everybody

    I'm trying to make round corners for contect menu.

    Qt Code:
    1. qApp->setStyleSheet("\
    2. QMenu {\
    3. background-color: black;\
    4. color: white;\
    5. font-family: Bodoni MT;\
    6. font-size: 18px;\
    7. border-radius: 10px;\
    8. border: 1px solid rgb(110, 110, 110);\
    9. }\
    10. QMenu::item{\
    11. padding-top: 4px;\
    12. padding-left: 5px;\
    13. padding-right: 15px;\
    14. padding-bottom: 4px;\
    15. }\
    16. QMenu::item:selected {\
    17. background: rgb(40, 40, 40);\
    18. }");
    To copy to clipboard, switch view to plain text mode 

    But I can still see the rectangular corner.
    Any Idea?

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMenu round corners

    From your code, it augth to work. When do you create the context menu, and how do you show it? Can you apply the style sheet directly to that QMenu object?

  3. #3
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMenu round corners

    Here is part of the code

    Qt Code:
    1. void GraphicsView::contextMenuEvent ( QContextMenuEvent * event )
    2. {
    3. QAction cm_exit("Exit",0);
    4. QAction cm_fitinview("Fit in View",0);
    5.  
    6. QMenu menu;
    7.  
    8.  
    9. menu.addAction(&cm_fitinview);
    10. menu.addAction(&cm_exit);
    11.  
    12. QAction* act = menu.exec(QCursor::pos());
    13. ....
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 
    If I apply style sheet directrly it gives same result( just tried)
    I just want to use same stylesheet for all menus in app.

  4. #4
    Join Date
    Jul 2010
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMenu round corners

    I just took the glance at your style-sheet. I am not sure, but it seems to me that many of the style-sheet properties you trying to use are not supported in Qt. There is a list of supported style-sheet properties in Qt documentation. Try find it and check it out.

  5. #5
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMenu round corners

    I did. Did not successeded.
    This is why I'm here

  6. #6
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMenu round corners

    Hi,

    test this:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. Q_INIT_RESOURCE(NBrowser);
    4.  
    5. QApplication app(argc, argv);
    6.  
    7. app.setStyleSheet("\
    8. QMenu {\
    9. background-color: black;\
    10. color: white;\
    11. font-family: Bodoni MT;\
    12. font-size: 18px;\
    13. border-radius: 10px;\
    14. border: 1px solid rgb(110, 110, 110);\
    15. }\
    16. QMenu::item{\
    17. padding-top: 4px;\
    18. padding-left: 5px;\
    19. padding-right: 15px;\
    20. padding-bottom: 4px;\
    21. }\
    22. QMenu::item:selected {\
    23. background: rgb(40, 40, 40);\
    24. }");
    25. MainWindow mainWin;
    26. mainWin.show();
    27. return app.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 
    it works on MAC
    with your stylesheet


    without your stylesheet


    hth,
    Ralf

  7. #7
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMenu round corners

    Do yoy see some black corners out of gray radius on the first scrrenshort? I wnat to avoid that.

  8. #8
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMenu round corners

    sorry i've misunderstood. I thought it does not display your css.
    I've played a bit with your css, but the black corners still remain.

    what's about using a black background-image with 10px radius like: background-image: url(:/images/blackradius.png); and background-color: transparent?
    i try it tomorrow...

  9. #9
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMenu round corners

    sounds like good idea. I'll try and let you know.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMenu round corners

    I don't think what you want will work with stylesheets because QMenu is a top-level widget and thus it is rectangular. If you want to round the borders, I'm afraid you will have to use QWidget::setMask() or set the translucency attribute and make sure only the part you want is painted (which you probably won't be able to do with stylesheets).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    medved6 (17th September 2010)

Similar Threads

  1. How to create region with rounded corners
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2009, 09:23
  2. QDialog with rounded corners
    By rossm in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2009, 23:31
  3. Mem'ries (like the corners of my mind)
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2007, 16:43
  4. Toplevel widget with rounded corners.
    By munna in forum Qt Programming
    Replies: 7
    Last Post: 18th August 2006, 20:46
  5. widget with rounded corners
    By sreedhar in forum Qt Programming
    Replies: 4
    Last Post: 7th June 2006, 12:18

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.