Hi,
i tried to define my own delegate editor for a custom Tree model used with a standard QTreeView.
seup is like this:
new QStandardItemEditorCreator<LineEditorCreator>();
factory
->registerEditor
(QVariant::String, lineEditorCreator
);
SceneModel model("test.xml");
view.setModel(&model);
view.show();
QItemEditorFactory *factory = new QItemEditorFactory();
QItemEditorCreatorBase *lineEditorCreator =
new QStandardItemEditorCreator<LineEditorCreator>();
factory->registerEditor(QVariant::String, lineEditorCreator);
QItemEditorFactory::setDefaultFactory(factory);
SceneModel model("test.xml");
QTreeView view;
view.setModel(&model);
view.show();
To copy to clipboard, switch view to plain text mode
this is the delegate (yes, it's only for testing):
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText USER
true)
public:
LineEditorCreator
(QWidget *widget
= 0): {
};
{
};
{
};
};
class LineEditorCreator : public QLineEdit
{
Q_OBJECT
Q_PROPERTY(QString text READ text WRITE setText USER true)
public:
LineEditorCreator(QWidget *widget = 0):
QLineEdit(widget)
{
};
QString text() const
{
return QLineEdit::text();
};
void setText(QString text)
{
QLineEdit::setText(text);
};
};
To copy to clipboard, switch view to plain text mode
i can also add the code for the model, but to my understanding it shouldn't interfere with the delegate.
without the custom delegate, editing works fine (so, yes, items are editable), with the delegate just nothing happens (and it's functions aren't called at all).
for testing purpose, i also tried with a standard QTreeWidget and the delegate works just fine there.
are there any special additions to be made to an model, so it supports the delegate?
Bookmarks