Unsolved regarding role in setData method of QAbstractItemModel
-
I am using qt.4.3.3 and qstyleditemdelegate.html is available fro,m qt4.4 so I cannot used qstyleditemdelegat please let me know if I impilimentation is ok
-
you can use QItemDelegate, the only difference is that QStyledItemDelegate uses stylesheets while QItemDelegate doesn't http://doc.qt.io/qt-4.8/qitemdelegate.html
-
can u point me exact example where QtreeView , customodel and a deletegate is used so that I understand the things better
Since storing a model pointer in View is my legacy code can I call
class myView::QTreeView {
}void myView::clicik() {
d_m->setData
} -
create a class that inherits from QItemDelegate and reimplement
virtual QWidget* createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const; virtual void setEditorData(QWidget * editor, const QModelIndex & index) const; virtual void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const; virtual QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; virtual void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const;
the widget returned from
createEditor
is displayed inside the view cell during editing,setEditorData
is used to load data from the model to the editor,setModelData
is used to save data from the editor to the model.updateEditorGeometry
is used to resize the editor in case the view gets resized during editing andsizeHint
tells the view how much space your image should takefinally you use QTreeView::setItemDelegateForColumn to set the delegate on the view and voilà
you can use QTreeView::setEditTriggers to chose when your editor should pop up ( QAbstractItemView::DoubleClicked I think in your case)
-
My question is what is advantage of using delegate since my legacy code my View owns the model pointer
is there any advandathe
-
not knowing what
myInstView
is I can't provide a definitive answer but handling your editor widget lifetime, positioning it correctly, resizing it correctly and handling when the editing starts and finishes all out of the box are pretty big advantages for me -
it is a object of QTreeVIew
-
That's not particularly helpful... what class is it? a button? a lineedit?
-
a QTreeView
-
I don't get the difference between myInstView and myView but it does not matter. Delegate is the answer.
My requirement is to edit the image when I double click on this image
if you want any more details you need to describe better how the image should be changed. is it selected from a combobox, is it a color button, is it loaded from file?