Important: Please read the Qt Code of Conduct -

How to change the spacing of icons in the toolbar?

  • 0_1516010026544_e914dfc0-31dc-4cab-aeba-c926b882cb46-image.png

    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

  • Moderators

    To change it globally you should create a proxy style and change the value you mentioned i.e.

    class CustomStyle : public QProxyStyle
        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
                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);

Log in to reply