qticonsqtoolbutton

qt qtoolbutton icon blurry


I have a problem where the icons used on QToolButtons on the QMenu attached to the QToolButton appear blurry. I have tried different sizes 24x24, 32x32, 64x64, different formats like png and svg but it always looks strange. On the image you can see the selected action and the top action on the menu have the same icon but the one in the menu is blurry. Even the one selected is not really sharp.

blurry icon

Is there some specific guideline for those icons or what am I doing wrong? The second and third icon is a build in icon which is I believe 24x24 svg but I was not able to reproduce.


Solution

  • Yes, you need to set different sizes of icons if you want them to look good under the QToolButon and in the QMenu, QT will pick up the size that fits best. One possible solution if you are using resource files could be like this:

    QIcon *myQIcon = new QIcon;
    myQIcon->addFile(":icon24.svg", QSize(24,24));
    myQIcon->addFile(":icon16.svg", QSize(16,16));
    
    mMyQAction->setIcon( *myQIcon );
    

    Detailed explanation can be found here: http://mithatkonar.com/wiki/doku.php/qt/icons