row height with QTreeView and delegates
Hi,
I am using a QTreeView to display some data. One column is edited using a QComboBox,for which I created a delegate like in the "Spin Box Delegate" example in the documentation. It all works great so far.
Unfortunately, the combo box's height is determined by the default row height of the QTreeView, which is too low.
I am able to add a sizeHint() method to the delegate, which is used by the view. But instead of setting a fixed height I'd like to use the sizeHint() of the combo box. The combo box is created inside createEditor() const method of the delegate, so I can't really use a class variable to store the size hint for later use. And I didn't find a method to get a an editor for a given ModelIndex either.
So am I thinking in the completely wrong direction or is there some other trick to it? I'm sure that's not the first case this has popped up, but I didn't find anything useful on Google.
Philipp
Re: row height with QTreeView and delegates
Hm, I now did it that way:
Code:
{
return createEditor(0, option, index)->sizeHint();;
}
This way the editor is created twice, which isn't really great but at least it works without having to use .
Is there an easier and better way?
Philipp
Re: row height with QTreeView and delegates
I'm not sure if there is a better way of doing this, but your MyDelegate::sizeHint() will be leaking memory if you do not delete the editor after calling its sizeHint(). Usually view takes this responsibility but you are not returning the editor to the view.
Re: row height with QTreeView and delegates
yuriry, thanks for the hint, that's true indeed. But still doesn't give me a better solution to my problem ;(
Re: row height with QTreeView and delegates
Have you had a chance to play with QTreeView::uniformRowHeights, QWidget::minimumHeight and QWidget::sizePolicy (the last two are for the editor)? Sorry, I cannot provide a better hint :(
Re: row height with QTreeView and delegates
Hi,
I am working on a similar problem without any solution at this time.
Quote:
Originally Posted by
Philipp
Hm, I now did it that way:
Code:
{
return createEditor(0, option, index)->sizeHint();;
}
How do you figure out, if an editor should be provided? Is this code not returning always the same sizeHint?
Lykurg
Re: row height with QTreeView and delegates
What have u set the delegate on ???
On the treeview , or the combobox ?? if on combobox, HOW ??
Re: row height with QTreeView and delegates
I have the same problem, the delegate could not return the correct sizeHint when the editors' sizes vary.