You need to call the constructor of your custom widget, in my case:
	
	
        CheckBoxDelegateWidget(const QStringList &texts, QWidget *parent = 0)
To copy to clipboard, switch view to plain text mode 
  But if your delegate widget is the same for all the column, you'd better create a local widget on the constructor of the delegate and save its sizes one time for all, then in  sizeHint you return the saved sizes:
	
	    : QStyledItemDelegate(parent), texts(texts)
{
    CheckBoxDelegateWidget editor(texts);
    widgeSizeHint_ = editor.sizeHint();
}
 
{
    return widgeSizeHint_;
}
        CheckBoxDelegate::CheckBoxDelegate(const QStringList &texts, QObject *parent)
    : QStyledItemDelegate(parent), texts(texts)
{
    CheckBoxDelegateWidget editor(texts);
    widgeSizeHint_ = editor.sizeHint();
}
QSize CheckBoxDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
    return widgeSizeHint_;
}
To copy to clipboard, switch view to plain text mode 
  
Digging in the Qt source code I've found:
	
	
        QWidget *QAbstractItemViewPrivate::editor(const QModelIndex &index,
                                          const QStyleOptionViewItem &options)
To copy to clipboard, switch view to plain text mode 
  which is what we need, but is a private function of QAbstractItemView. I think it is because the editor are created only when needed (when you double click a cell), so if it isn't created and you call this function, it creates a new editor but for the ItemView no editor is open so it doesn't know when delete it and it remains in memory.
				
			
Bookmarks