Results 1 to 5 of 5

Thread: How to change Icon size in QMenu?

  1. #1
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to change Icon size in QMenu?

    Hi, I can't find how to change the size of icons in QMenu. I don't see any method like "setIconSize()" for QMenu. Simple code:

    action = new QAction(icon, "Settings", this);
    menu->addAction(action);

    All icons that I create like this appear in the menu in small size (a bit smaller than in all other programs). Is it possible somehow to increase the size of icons? I use *.svg and *.png icons of different sizes from 48x48 to 128x128, but when my program runs, all icons have the same default and small size.

    Thank you!

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change Icon size in QMenu?

    Quote Originally Posted by alex chpenst View Post
    Hi, I can't find how to change the size of icons in QMenu. I don't see any method like "setIconSize()" for QMenu. Simple code:

    action = new QAction(icon, "Settings", this);
    menu->addAction(action);

    All icons that I create like this appear in the menu in small size (a bit smaller than in all other programs). Is it possible somehow to increase the size of icons? I use *.svg and *.png icons of different sizes from 48x48 to 128x128, but when my program runs, all icons have the same default and small size.

    Thank you!
    On ToolBar i write:
    toolBar->setIconSize(QSize(_MAINICONSIZE_,_MAINICONSIZE_)) ;

    on the place that you play action i am sure is the same method.....

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to change Icon size in QMenu?

    Please search the forums.

    QMenu uses styles to decide the correct icon size for the platform in use. You can trick QMenu to use larger icon size with a custom style. For more details, see thread: http://www.qtcentre.org/forum/f-qt-p...cons-4173.html.
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    alex chpenst (3rd September 2008)

  5. #4
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change Icon size in QMenu?

    Thanks a lot, it works fine. With the help of this link and some code from there I came to the following (a bit repeating but more detailed).

    1. Find out which style you use:
    Qt Code:
    1. QApplication app(argc, argv);
    2. std::cout << "Default Style: " << app.style()->metaObject()->className() << std::endl;
    To copy to clipboard, switch view to plain text mode 

    In my case QCleanlooksStyle is used by default.

    2. make mystyle.h
    Qt Code:
    1. #include <QCleanlooksStyle>
    2. class MyStyle: public QCleanlooksStyle
    3. {
    4. Q_OBJECT
    5. public:
    6. int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const {
    7. int s = QCleanlooksStyle::pixelMetric(metric, option, widget);
    8. if (metric == QStyle::PM_SmallIconSize) {
    9. s = 20;
    10. }
    11. return s;
    12. }
    13. };
    To copy to clipboard, switch view to plain text mode 

    3. Apply your style to your application
    Qt Code:
    1. #include "mystyle.h"
    2. ...
    3. QApplication app(argc, argv);
    4. app.setStyle(new MyStyle);
    To copy to clipboard, switch view to plain text mode 

    That's it. If another style is used, e.g. QPlastiqueStyle, replace QCleanlooksStyle with QPlastiqueStyle and it should work as well.

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to change Icon size in QMenu?

    You could have also used a proxy style as proposed in the another thread.
    J-P Nurmi

Similar Threads

  1. Replies: 1
    Last Post: 2nd August 2008, 16:46
  2. Replies: 2
    Last Post: 21st May 2007, 22:12
  3. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 20:16
  4. Difficult:Dynamic Icon size change?!?
    By nupul in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2006, 10:39
  5. tool bar icon size looking small???
    By darpan in forum Qt Tools
    Replies: 7
    Last Post: 31st March 2006, 17:38

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.