Results 1 to 11 of 11

Thread: How to change the icon size in QMenu?

  1. #1
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation How to change the icon size in QMenu?

    Hi, I am a beginner of Qt, and I am also a foreigner. Please ignore all the strange spelling and grammar error~Thanks a lots~

    Now I got some issue with the QMenu. I've already know the QStyle::PM_SmallIconSize in my style. I have set that value to 50.
    But the problem is: the blank has been increase. The image didn't change. Still 16x16.

    I have try to find out some other way to change the size of image. But nothing seems to work.

    What can I do about this? Thanks for everyone's help!

  2. #2
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to change the icon size in QMenu?

    I think this is what you want.
    A simple search on google gives me the link.

    http://www.qtcentre.org/threads/1574...-size-in-QMenu
    Last edited by karankumar1609; 14th June 2013 at 10:34.

  3. #3
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the icon size in QMenu?

    Thanks for your quick reply.

    I've already read this. But it seems works nothing.
    Actually I changed PM_SmallIconSize value to 50. But only the height of QMenuItem increase. The image didn't changed.
    a.jpg
    This is what the SmallIconSize changed works.

  4. #4
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to change the icon size in QMenu?

    Search is the best friend of yours.
    Have some good search and got:
    http://www.qtcentre.org/threads/4173...r-resize-icons


    Try this one ... it will resolve your problem.


    CHEERS...!!!

  5. #5
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the icon size in QMenu?

    Thanks Again, but there might be some problems with my own style...
    I've find out where the problem might be.

    This article I have read, too. These two article is actually the same one. Because the solution is totally the same.
    Now I'm busy coding with my own style, thanks all the same~

  6. #6
    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: How to change the icon size in QMenu?

    What is the size of the images you are setting as icons?
    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.


  7. #7
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the icon size in QMenu?

    The icon is 30px30p. But when I add the icon to QMenu, it looks just the same like the snapshot on #3.


    Added after 4 minutes:


    Actually, I find out that I have changed Style::drawMenuItem in my own style, and I rewrite it. I draw the new icon and now it really works.
    But a new problem: I use switch(opt->menuItemType) to judge the type and redraw the menu, I find out that the MenuItem which I put the mouse over it doesn't changed. I searched for the opt->state, but nothing seems to work. Could you please help me with this problem? Thanks a million~
    Last edited by harinlen; 16th June 2013 at 07:57.

  8. #8
    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: How to change the icon size in QMenu?

    Quote Originally Posted by harinlen View Post
    The icon is 30px30p. But when I add the icon to QMenu, it looks just the same like the snapshot on #3.
    What if you set a larger icon? As far as I remember Qt does not upscale icons.
    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.


  9. #9
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the icon size in QMenu?

    I have tried several times, nothing happened. The Size of Icon is just look like that snapshot.
    I'm so sorry that I forget to tell you about the style which I rewrite:

    Qt Code:
    1. void KreogistCuteStyle::drawControl(ControlElement element,
    2. const QStyleOption *opt,
    3. const QWidget *w) const
    4. {
    5. switch(element)
    6. {
    7. case CE_MenuItem:
    8. {
    9. const QStyleOptionMenuItem *_opt_menu_item=
    10. qstyleoption_cast<const QStyleOptionMenuItem *>(opt);
    11. if(_opt_menu_item != nullptr)
    12. {
    13. drawMenuItem(_opt_menu_item,p,w);
    14. }
    15. break;
    16. }
    17.  
    18. default:
    19. style->drawControl(element,opt,p,w);
    20. break;
    21. }
    22. }
    23.  
    24. void KreogistCuteStyle::drawMenuItem(const QStyleOptionMenuItem *opt,
    25. const QWidget *w) const
    26. {
    27. switch(opt->menuItemType)
    28. {
    29. case QStyleOptionMenuItem::Normal:
    30. {
    31. int iRectX=opt->rect.x(),
    32. iRectY=opt->rect.y(),
    33. iRectW=opt->rect.width(),
    34. iRectH=opt->rect.height();
    35. QPen pen;
    36.  
    37. if(opt->state == State_Selected)
    38. //opt->state == State_HasFocus)
    39. {
    40. p->setBrush(opt->palette.highlight());
    41. p->drawRect(opt->rect);
    42. pen.setColor(QColor(0xf6,0xcd,0x32));
    43. p->setPen(pen);
    44. p->fillRect(opt->rect,Qt::BrushStyle::SolidPattern);
    45. qDebug()<<"asdf";
    46. }
    47. else
    48. {
    49. ;
    50. }
    51. if(!opt->icon.isNull())
    52. {
    53. p->drawPixmap(13,
    54. iRectY + (iRectH - 30)/2,
    55. 30,
    56. 30,
    57. opt->icon.pixmap(30, 30));
    58. p->drawText(50,
    59. iRectY,
    60. iRectW,
    61. iRectH,
    62. Qt::AlignVCenter,
    63. opt->text);
    64. }
    65. else
    66. {
    67. p->drawText(50,
    68. iRectY,
    69. iRectW,
    70. iRectH,
    71. Qt::AlignVCenter,
    72. opt->text);
    73. }
    74. pen.setColor(QColor(0,0,0));
    75. p->drawLine(iRectX,iRectY+iRectH-1,iRectX+iRectW,iRectY+iRectH-1);
    76. break;
    77. }
    78. default:
    79. style->drawControl(CE_MenuItem,opt,p,w);
    80. }
    81. }
    To copy to clipboard, switch view to plain text mode 

    I rewrite these two things to resize the icon and draw lines, but I find out the selected item doesn't change into highlight. How can I solve the problem?

  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: How to change the icon size in QMenu?

    If you are drawing the icon yourself and fixing its size at 30px then I don't know why you would expect the size of the icon to be different.
    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. #11
    Join Date
    Jun 2013
    Posts
    13
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the icon size in QMenu?

    Well, I solved this problem by using this style. Thanks a lot !

Similar Threads

  1. problem with QMenu::icon border
    By sattu in forum Qt Programming
    Replies: 1
    Last Post: 2nd July 2013, 14:27
  2. Style QMenu::item's icon
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2013, 14:59
  3. Icon in a QMenu doesn't show up on Linux
    By agarny in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2011, 14:58
  4. How to change Icon size in QMenu?
    By alex chpenst in forum Qt Programming
    Replies: 4
    Last Post: 3rd September 2008, 14:16
  5. Difficult:Dynamic Icon size change?!?
    By nupul in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2006, 09:39

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.