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. QToolBar - real Icon Size / Minimum Size
QtWS25 Last Chance

QToolBar - real Icon Size / Minimum Size

Scheduled Pinned Locked Moved General and Desktop
sizeqactioniconiconsqtoolbarsizehintsizepolicy
2 Posts 2 Posters 2.7k Views
  • 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.
  • C Offline
    C Offline
    Cluosh
    wrote on 23 Aug 2015, 13:08 last edited by
    #1

    Greetings!

    I'm trying to figure out the minimum toolbar size for all icons to be visible. Since I couldn't find any in-built functionality for this, I tried calculating the minimum size from the size of the icons.

    I've realized, that QToolBar draws an additional border around the icons, which breaks the minimum-size calculation using iconSize().

    My questions:

    • Is there any way to disable the additional QToolBar border around icons?
    • If not, is there any reliable way to query the size of icons including this border?
    • Is there an easy way to get the minimum size of a QToolBar, where all icons are visible?
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 23 Aug 2015, 19:15 last edited by
      #2

      The thing is that toolbars don't really display icons. They display widgets (that can have icons). By default when you add an action to a toolbar a QToolButton is created for it, but you are not limited to that and can add any widget e.g. an expanding line edit, combobox or a button with an icon and text. All of these can have different size policies, be expanding or have a custom stylesheet applied.
      All of this makes calculating such size not feasible because how would you calculate it if a widget can change its size.

      What I'm saying is that yours is a special, very specific case (with just icons), and as such you need to handle it yourself if you want to.

      To answer your questions:

      • It's not one thing that adds the space. There are couple of aspects that can contribute. You can control some(or all?) of them with stylesheets e.g. set padding of the toolbar and toolbuttons to 0 and margins and borders of the toolbuttons. By default all of these depend on a style and will vary across computers. You also need to be careful to consider the size of the toolbar handle (if it's movable) as its size depends on the active style. You also need to consider that if the icon is narrower than the iconSize then there's gonna by space left anyway.
      • nope, AFAIK it can vary from one item of the toolbar to another if you set it this way
      • nope and just out of curiosity - why do you need that? The bar will display an arrow button that will let you see the overflowing items. Also such calculated size would be useless as the window can be resized and thus the toolbar too (unless you're doing some really fancy layout).
      1 Reply Last reply
      0

      2/2

      23 Aug 2015, 19:15

      • Login

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