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.
-
What icon size do you have in mind ?
What is the size of the image you are loading ? -
Then again, what size do you have in mind ?
-
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
-
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(); }