Resize treeView row with delegate editor
-
Hi
If you have SizeHint ( sample is for fitting to a pixmap)class ItemDelegate : public QItemDelegate { public: QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const { const TreeItem* ti(static_cast<TreeItem*>(index.internalPointer())); if(ti->pixmap()) return ti->pixmap()->size(); QItemDelegate::sizeHint(option,index); } };
Then maybe you just need to disable
http://doc.qt.io/qt-5/qtreeview.html#uniformRowHeights-prop
if its on.
Also the docs says
"Note: If the editor size hint is bigger than the cell size hint, then the size hint of the editor will be used."
So it sounds like it can also have a sizehint?
Did you try that route? -
Hi
If you have SizeHint ( sample is for fitting to a pixmap)class ItemDelegate : public QItemDelegate { public: QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const { const TreeItem* ti(static_cast<TreeItem*>(index.internalPointer())); if(ti->pixmap()) return ti->pixmap()->size(); QItemDelegate::sizeHint(option,index); } };
Then maybe you just need to disable
http://doc.qt.io/qt-5/qtreeview.html#uniformRowHeights-prop
if its on.
Also the docs says
"Note: If the editor size hint is bigger than the cell size hint, then the size hint of the editor will be used."
So it sounds like it can also have a sizehint?
Did you try that route?@mrjj Thanks for your reply. But no It doesn't work.
The problem is that QAbstractItemDelegate::createEditor() doesn't call sizeHint. The Widget editor is adjusted to the row height. I want to adjust the row height to the editor.
In your pixmap example, the row keep the same size everytime. For me, the row must be changed when editor is called . -
@mrjj Thanks for your reply. But no It doesn't work.
The problem is that QAbstractItemDelegate::createEditor() doesn't call sizeHint. The Widget editor is adjusted to the row height. I want to adjust the row height to the editor.
In your pixmap example, the row keep the same size everytime. For me, the row must be changed when editor is called .@dridk2
Hmm, I was under the impression that it would when
uniformRowHeights is off. Also it would use Editors SizeHint if cell size is smaller.
I dont know how else its possibleI would wait and see if VRonin would be so kind to provide input as might know
a good way. This cant be that uncommon use case. :) -
If I understand correctly:
Use the options widget dimensions in sizehint(), to set the row height.//in sizeHint(): QStyleOptionViewItem options = option; initStyleOption(&options, index); int scrollBarrWidth = options.widget->style()->pixelMetric(QStyle::PM_ScrollBarExtent); QRect rowRect(0,0,(options.widget->rect().right()-scrollBarrWidth),options.widget->rect()..bottom());
Then in my TreeView I reimplement resizeEvent, to shange the row every time the treeView changes it's dimensions
void MyTreeView::resizeEvent(QResizeEvent *e) { if(model() != Q_NULLPTR){ model()->layoutChanged(); } QTreeView::resizeEvent(e); }
I did not test the first code block, but I use the options.widget->rect().right() im my app.
-
The first size hint being in the Editor class?