Results 1 to 11 of 11

Thread: QStyledItemDelegate and editor pointer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    166
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 14 Times in 14 Posts

    Default Re: QStyledItemDelegate and editor pointer

    Nice hint but in my case will not work because my custom widget sizeHint() changes dynamically depending on the contents in it.

    When I create the editor I have other data class which I use to populate the data in the editor widget. After the data is populated the size hint will be calculated. The constructor for the delegate is called only once per item, and if my custom editor changes it's sizeHint the item will not be with proper size.

    I have tried with mutable variable which I use in the function createEditor() to obtain correct sizeHint but it seems that it is too late, because the TreeView had already called the virtual funtion sizeHint() and I get improper item sizes...

    I hope I was able to explain my case clear and that there is solution to this.

  2. #2
    Join Date
    Jun 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Default Re: QStyledItemDelegate and editor pointer

    Maybe I've lost you, but as tbscope said, something like this doesn't work?
    Qt Code:
    1. QSize CheckBoxDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const
    2. {
    3. CheckBoxDelegateWidget editor( yourClassDataList.value( index.row() ) );
    4. return editor.sizeHint();
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Nero for this useful post:

    The Storm (20th September 2010)

  4. #3
    Join Date
    Aug 2007
    Posts
    166
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 14 Times in 14 Posts

    Default Re: QStyledItemDelegate and editor pointer

    Yes this will do the trick. The only thing is that both methods are "hacks" and leads to overhead... Anyway if this is the only way I don't have much of a choise.

Similar Threads

  1. QStandardItem, QStyledItemDelegate, and QWebView
    By enlightened_j in forum Newbie
    Replies: 1
    Last Post: 16th August 2010, 09:44
  2. QStyledItemDelegate with custom QWidget editor
    By stefanadelbert in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2010, 00:19
  3. Setting Format in a QStyledItemDelegate
    By Airswoop1 in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2009, 23:01
  4. Replies: 5
    Last Post: 30th March 2008, 17:53
  5. Replies: 6
    Last Post: 22nd June 2007, 23:20

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.