c++qtdelegatesqtableviewqplaintextedit

Setting the Height of a QPlainTextEdit Delegate in a QTableView


I'm working here on a project and currently I'm stuck on the following problem. It is about a QTableView which has a column called "Description", the cells of this column contain a QPlainTextEditDelegate. I'm failing on setting the Height of the QPlainTextEdit everytime it is entered. Right now it behaves like a QLineEdit until I drag the row ( in which I'm active at that time ) of the QTableView larger.

What I want to do is to change the Height of the QPlainTextEdit once I entered it. What are your suggestions? How can I proceed to get this thing done?

Thank you all in advance!

BTW Sorry for my poor english :/

edit:

Ok I solved it, but without sizeHint, I used updateEditorGeometry :

void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem & option, const QModelIndex & index ) const;

And inside this Method, you can set the width or height like you want

editor->setGeometry(option.rect.x(),option.rect.y(),<your_width>,<your_height>);

But thank you anyway!


Solution

  • You should reimplement QAbstractItemDelegate::sizeHint method to return expected height when you create your editor. I don't think that it's necesary to emit QAbstractItemDelegate::sizeHintChanged signal after creating editor, but documentation doesn't say anything. If it doesn't work without it, you should emit sizeHintChanged after returning created editor widget to notify view of need to change row height.