Solved Change the icon size to a QAction
-
Hello ... I would like to resize the icon of a QAction.
I have a set of actions that I build dynamically to which I add a corresponding icon, but the size of this does not allow to define the image well and I would like to increase the size without having to increase the size of the text. -
Hi,
How are you building your actions and icons ?
Where are your actions located in your UI ? -
@SGaist said in Change the icon size to a QAction:
a
hi...I have a button to which I put a menu with dynamic actions created in a cycle. Then the most significant of the actions should be the icon that is what identifies them, so I need to resize to be able to see the image better. Do you think you can help me?
-
Maybe but showing your code where you are making your QIcon objects would help a lot.
-
this is the code:
QMenu *menu = new QMenu; for(int i = 0; i < TotalAction; i++) { QAction *action = new QAction(QIcon("icon_path"), "name"); menu->addAction(action); } pushbutton->setMenu(menu);
the I want to resize the icon.. please HELP ME
-
What icon size do you have in mind ?
What is the size of the image you are loading ? -
I want to resize the icon of the QAction, so it can be visible in detail.
The size of the uploaded image is 55x40 pixels -
Then again, what size do you have in mind ?
-
I want the original size of the image. The problem is that the size of the QAction icon is very small, because it resizes that image size
-
One thing that passed me by: you are setting your icon on a menu. The size used for the icon in this case is decided by the style to follow the platform standard. If you want to customise that part you'll have to implement your own style.
-
Or use a QProxyStyle
-
@SGaist show me an example
-
The doc have sample :) Just after important info..
Anyway, what you are after is something like
#include <QProxyStyle> class MyProxyStyle: public QProxyStyle { Q_OBJECT public: MyProxyStyle(QStyle* style = 0) : QProxyStyle(style) { } MyProxyStyle(const QString& key) : QProxyStyle(key) { } virtual int pixelMetric(QStyle::PixelMetric metric, const QStyleOption* option = 0, const QWidget* widget = 0 ) const { switch ( metric ) { case QStyle::PM_SmallIconSize: return 200; // here u want pixmaps size i assume default: return QProxyStyle::pixelMetric( metric, option, widget ); // return default values for the rest } } };
Note that you violate most user interface guidelines by this.
However, i have done it to make menus good for touch activation so it has its use cases but
it also means that you app will not play well with a platform that it self have adjusted heights.
Like for seeing impaired etc.To use
int main(int argc, char* argv[]) { QApplication a(argc, argv); a.setStyle(new MyProxyStyle() ); MainWindow w; w.show(); return a.exec(); }
-
@mrjj All good, but there is a problem which is that in the application I have another menu that I do not want to resize to the icons