how to set height of single QTreeWidgetItem in QTreeWidget
-
Hi and welcome to the forums
One way would be.class HeightItemDelegate : public QStyledItemDelegate { public: HeightItemDelegate(QObject *poParent = nullptr) : QStyledItemDelegate(poParent) {} QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override { QSize oSize = QStyledItemDelegate::sizeHint(option, index); int height = index.model()->data( index, Qt::UserRole ).toInt(); if ( height ) { oSize.setHeight(height); } return oSize; } }; ...... //use the delegate HeightItemDelegate *delegate= new HeightItemDelegate(this); ui->treeWidget->setItemDelegate(delegate); // set height for an item via model auto model = ui->treeWidget->model(); // get index QModelIndex indx = ui->treeWidget->model()->index(1, 0); // assing the height value model->setData( indx, 50 , Qt::UserRole);