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 get the effective icon size used in a QTreeView?
Qt 6.11 is out! See what's new in the release blog

How to get the effective icon size used in a QTreeView?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 808 Views 2 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.
  • T Offline
    T Offline
    tempus_fugit
    wrote on last edited by
    #1

    This seems like a really basic question, but I have been unable to find out how to do this: How do I retrieve the actual icon size that is used in a QTreeView? When I create a QTreeView and call iconSize() I get the default value of (-1, -1), which apparently indicates that the size will be based on the font metrics. However, it is unclear in what way. For instance, the actual size does not correspond to tree_view->fontMetrics().height(). Is there a reliable way to retrieve the icon size? All items are just icon+text and I call setUniformRowHeights(true) in case that makes any difference.
    The background ist that I want to dynamically generate bitmap icons at the right size, so they are not scaled when being used in the tree view.

    M 1 Reply Last reply
    0
    • T tempus_fugit

      This seems like a really basic question, but I have been unable to find out how to do this: How do I retrieve the actual icon size that is used in a QTreeView? When I create a QTreeView and call iconSize() I get the default value of (-1, -1), which apparently indicates that the size will be based on the font metrics. However, it is unclear in what way. For instance, the actual size does not correspond to tree_view->fontMetrics().height(). Is there a reliable way to retrieve the icon size? All items are just icon+text and I call setUniformRowHeights(true) in case that makes any difference.
      The background ist that I want to dynamically generate bitmap icons at the right size, so they are not scaled when being used in the tree view.

      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @tempus_fugit said in How to get the effective icon size used in a QTreeView?:

      The background ist that I want to dynamically generate bitmap icons at the right size, so they are not scaled when being used in the tree view.

      You can return the height of a row according to the icon size you want in Qt::SizeHintRole in your item model.

      T 1 Reply Last reply
      0
      • M mpergand

        @tempus_fugit said in How to get the effective icon size used in a QTreeView?:

        The background ist that I want to dynamically generate bitmap icons at the right size, so they are not scaled when being used in the tree view.

        You can return the height of a row according to the icon size you want in Qt::SizeHintRole in your item model.

        T Offline
        T Offline
        tempus_fugit
        wrote on last edited by
        #3

        @mpergand said in How to get the effective icon size used in a QTreeView?:

        @tempus_fugit said in How to get the effective icon size used in a QTreeView?:

        The background ist that I want to dynamically generate bitmap icons at the right size, so they are not scaled when being used in the tree view.

        You can return the height of a row according to the icon size you want in Qt::SizeHintRole in your item model.

        Thanks. Yes, that would work but that only shifts the problem. I do not really want the burden of controlling the row height, because that would mean that I would have to compute a suitable value for the row height. I would really prefer letting QTreeView work out the row height for me based on the natural height of the items.

        M 1 Reply Last reply
        0
        • T tempus_fugit

          @mpergand said in How to get the effective icon size used in a QTreeView?:

          @tempus_fugit said in How to get the effective icon size used in a QTreeView?:

          The background ist that I want to dynamically generate bitmap icons at the right size, so they are not scaled when being used in the tree view.

          You can return the height of a row according to the icon size you want in Qt::SizeHintRole in your item model.

          Thanks. Yes, that would work but that only shifts the problem. I do not really want the burden of controlling the row height, because that would mean that I would have to compute a suitable value for the row height. I would really prefer letting QTreeView work out the row height for me based on the natural height of the items.

          M Offline
          M Offline
          mpergand
          wrote on last edited by
          #4

          @tempus_fugit
          There's a protected method:
          [protected] int QTreeView::rowHeight(const QModelIndex &index) const

          1 Reply Last reply
          0

          • Login

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