Results 1 to 8 of 8

Thread: row height with QTreeView and delegates

  1. #1
    Join Date
    Mar 2006
    Location
    Bavaria/Germany
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  2. #2
    Join Date
    Mar 2006
    Location
    Bavaria/Germany
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: row height with QTreeView and delegates

    Hm, I now did it that way:

    Qt Code:
    1. QSize MyDelegate::sizeHint(const QStyleOptionViewItem & option,
    2. const QModelIndex & index) const
    3. {
    4. return createEditor(0, option, index)->sizeHint();;
    5. }
    To copy to clipboard, switch view to plain text mode 

    This way the editor is created twice, which isn't really great but at least it works without having to use
    Qt Code:
    1. return QSize(x,y);
    To copy to clipboard, switch view to plain text mode 
    .

    Is there an easier and better way?

    Philipp

  3. #3
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  4. #4
    Join Date
    Mar 2006
    Location
    Bavaria/Germany
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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 ;(

  5. #5
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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 View Post
    Hm, I now did it that way:
    Qt Code:
    1. QSize MyDelegate::sizeHint(const QStyleOptionViewItem & option,
    2. const QModelIndex & index) const
    3. {
    4. return createEditor(0, option, index)->sizeHint();;
    5. }
    To copy to clipboard, switch view to plain text mode 
    How do you figure out, if an editor should be provided? Is this code not returning always the same sizeHint?


    Lykurg

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: row height with QTreeView and delegates

    What have u set the delegate on ???
    On the treeview , or the combobox ?? if on combobox, HOW ??

  8. #8
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.