tags:

views:

226

answers:

1

Hi everyone,

I want to make editable cells with multi-lines content in QTreeWidget and I use for this purpose QPlainTextEdit as a delegate. I need to set proper size to all rows that switching between editing and displaying went smooth, without any visible changes.

rect = textEdit.blockBoundingRect(textEdit.firstVisibleBlock())
  • with this I can find out the height I need to set for the row, but I missing the place where I can do it.

How can i set proper height to QTreeWidget's rows on initialization stage and how to handle it's changes?

Thank you in advance, Serge

+1  A: 

You need to reimplement delegate's sizeHint(). It will automatically handle row's height and width. And note, that QTreeWidget::uniformRowHeight property must be false in this case, though it will slow tree element rendering if it contains many rows.

Max
serge
I haven't figure out how to to this right, when needed to do that. Workaround I've used was to save delegate's editor size hint in the model's SizeHintRole, when editing ends and use it when there is no editor shown. Or, preferrably, you can use FontMetrics class, cause the bounding rectangle of your item can be obtained from the text it holds.So, you'd ask, 'what about the initialization stage'. You can do it several ways: use FontMetrics class to set up SizeHintRole or obtain it from invisible QPlainTextEdit, placing proper text to it and demanding it's bound. rect.
Max