How to change the spacing of icons in the toolbar?
Unsolved
General and Desktop
-
My toolbar is like above. I want change my icons spacing. It seems that there is no special function to achieve it. In QStyle, I find this variable QStyle:: PM_ToolBarItemSpacing, is this variable changed? Or what other methods should be done?
Thanks for any advice!
Qt Creator 5.9.1+windows -
To change it globally you should create a proxy style and change the value you mentioned i.e.
class CustomStyle : public QProxyStyle { public: int pixelMetric(PixelMetric metric, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const override { if (metric == QStyle:: PM_ToolBarItemSpacing) return 100; //or whatever you want else return QProxyStyle::pixelMetric(metric, option, widget); } };
and then set it on the app object in
main()
:int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setStyle(new CustomStyle); ...