Results 1 to 10 of 10

Thread: Two icons for each item in QMenu?

  1. #1
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Question Two icons for each item in QMenu?

    Hello,

    Is there a way to set two separate icons for each QMenu item?

    So that menu would look like this:
    [ ] [ ] Item1
    [ ] [ ] Item2
    [ ] [ ] Item3
    [ ] [ ] Item4


    Thank you in advance.

  2. #2
    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: Two icons for each item in QMenu?

    No, I don't think so. But you can compose an icon from two images.
    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.


  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Two icons for each item in QMenu?

    You can't do that "out of the box" with QMenu. But you could write your own QMenu subclass that supports two icons.

  4. #4
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Two icons for each item in QMenu?

    @wysota

    I've checked this already. When I set item's icon to 16x32 px image, it will be scaled down to 8x16.


    @Brandybuck

    I looked through qmenu.cpp, but I cannot find any place where the icon and label are drawn or inserted into layout :/

  5. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Two icons for each item in QMenu?

    Menu items are normally drawn with QStyle, so you would have to do your own drawing of it. I think Wysota's suggestion will be easier.

  6. #6
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Two icons for each item in QMenu?

    Well, what wysota said is quite a good idea. But the icons are getting scaled down.

    I tried to change their appearance with ::setStyleSheet() both for qApp and the menu. But no luck.
    I tried setting style for QMenu::item::icon, QMenu::icon and some more combinations.

    Did I do something wrong, or there is no way to style the icon to have 32px width?

  7. #7
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Two icons for each item in QMenu?

    Try calling setStyle() on your menu, with a style defined like this:

    Qt Code:
    1. class myStyle: public QPlastiqueStyle
    2. {
    3. Q_OBJECT
    4. public:
    5. int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
    6. {
    7. if (metric == QStyle::PM_SmallIconSize)
    8. return 32; // default is 16
    9. else
    10. return QPlastiqueStyle::pixelMetric(metric, option, widget);
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Two icons for each item in QMenu?

    @drhex

    This works fine, however it changes the style of the menu making the application looking bad.

    It seems icon size depends on the style and how it decides to draw it. And only QPlastiqueStyle respects PM_SmallIconSize value.

  9. #9
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Lightbulb Re: Two icons for each item in QMenu?

    I have created WideIconsMenu class that should solve this problem.

    It uses ProxyStyle for Qt4 from QtCentre's wiki, and similar class for Qt3. Both Qt3 and Qt4 are supported.

    Multiple icons cannot be used, however WideIconsMenu draws the icons on its own, so icons of any width are supported. Everything you have to do is to compose an icon from several images.
    See included examples for more details.

    The code is available under GPLv3 license.

    If you find a bug, or have a suggestions, please send me an email.
    Attached Files Attached Files

  10. #10
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Lightbulb Re: Two icons for each item in QMenu?

    Since Qt 4.6 and above provides QProxyStyle class, the ProxyStyle code is no longer needed.

    The attached archive contains 3 versions of WideIconsMenu:
    - for Qt 3 (no changes)
    - for Qt 4.x (no changes)
    - for Qt 4.6+ (new)
    Attached Files Attached Files

Similar Threads

  1. Making icons in QMenu Bigger?
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 28th October 2008, 07:54
  2. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37

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.