Results 1 to 4 of 4

Thread: QMenu always displays icons aty 16x16 px

  1. #1
    Join Date
    Apr 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QMenu always displays icons aty 16x16 px

    Hi - I am using QMenu, and I am using a large font in the menu. I am providing 24x24 pixel icons to the QMenu when I add actions to it, but when the menu renders, my icons have been "downsized" to 16x16 pixels, and look too small next to my larger menu text.

    I could not find out how to set the icon size -- I tried setting the style of the menu to this style sheet, but no joy. Any help is much appreciated!

    QMenu::item { padding: 2px 32px 2px 20px; }
    QMenu::item:selected { background-color: blue; color: white }
    QMenu::icon { width:24px; height:24px; }
    QMenu::indicator { width:24px; height:24px; }

    - Greg

  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: QMenu always displays icons aty 16x16 px

    I guess you will need to provide a new style. You can derive it from the style classes in Qt.

  3. #3
    Join Date
    Apr 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMenu always displays icons aty 16x16 px

    Thank you for the pointer... here's what I tried.

    I derived my own style from QPlastiqueStyle and overrode the pixelMetric() function. QPlastiqueStyle calls its pixelMetric() method when it is drawing a menu item, to find out the pixel metrics for PM_SmallIconSize. My overridden class re-implements the virtual pixelMetrics like this:

    Qt Code:
    1. int MyStyle::pixelMetric (PixelMetric metric, const QStyleOption* option, const QWidget* widget)
    2. {
    3. qDebug () << "my menu style pixelMetric called!";
    4.  
    5. if (metric == PM_SmallIconSize)
    6. {
    7. return 24;
    8. }
    9. else
    10. {
    11. return QPlastiqueStyle::pixelMetric (metric, option, widget);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Next, I instantiate an object of type MyStyle and pass it to my QMenu's setStyle method:
    Qt Code:
    1. MyStyle myStyle;
    2. QMenu menu;
    3.  
    4. menu.setStyle (&myStyle);
    To copy to clipboard, switch view to plain text mode 

    However, when I pop up that menu, my pixelMetric function (in my derived class) never gets called -- and the icon is still displayed at 16x16. Any suggestions?

    Thanks


    Greg

  4. #4
    Join Date
    Apr 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Smile Joy!

    Joy!

    I was forgetting the 'const' at the end of my method override for the pixelMetric function. So I wasn't really overriding the function in the base class, due to the signature mismatch (base class's method was const, mine wasn't).

    Making my pixelMetric function const solved the problem.

    Thanks for your help!


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. Making icons in QMenu Bigger?
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 28th October 2008, 07:54

Tags for this Thread

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.