Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change the spacing of icons in the toolbar?

How to change the spacing of icons in the toolbar?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 812 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Qt_crazyerQ Offline
    Qt_crazyerQ Offline
    Qt_crazyer
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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);
      
          ...
      
      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved