How to get the effective icon size used in a QTreeView?
-
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 aQTreeViewand calliconSize()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 totree_view->fontMetrics().height(). Is there a reliable way to retrieve the icon size? All items are just icon+text and I callsetUniformRowHeights(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. -
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 aQTreeViewand calliconSize()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 totree_view->fontMetrics().height(). Is there a reliable way to retrieve the icon size? All items are just icon+text and I callsetUniformRowHeights(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.@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.
-
@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.
@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.
-
@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.
@tempus_fugit
There's a protected method:
[protected] int QTreeView::rowHeight(const QModelIndex &index) const