
Originally Posted by
ctgrund
am doing fine with QTreeView, abstract models, and delegates.
What I need now is the following: In the tree there is a string and if I would like to edit it there should come something like the ... button.
Then your delegate will create a button as the editor widget.

Originally Posted by
ctgrund
When I click on it the file dialog pops up.
Then you need to connect your button's clicked() signal to a slot that runs the file dialog.
You could have your own button class that does that internally and has a member for the file name, which is set in setEditorData and read in setModelData.
Or using a dynamic property on a normal QPushButton or storing the name elsewhere and accessing it from the slot that shows the dialog.
I would go for a base class that encapsulates the dialog step
{
Q_OBJECT
public:
{
connect( this, SIGNAL(clicked()), this, SLOT(onClicked()) );
}
void setEditorData
( const QVariant &data
);
// store data delegate gets in setEditorData QVariant modelData
() const;
// return data that setModelData should store.
protected slots:
virtual void onClicked() = 0; // implemented by sub classes
}
class EditorButton : public QPushButton
{
Q_OBJECT
public:
explicit EditorButton( QWidget *parent ) : QPushButton( parent )
{
connect( this, SIGNAL(clicked()), this, SLOT(onClicked()) );
}
void setEditorData( const QVariant &data ); // store data delegate gets in setEditorData
QVariant modelData() const; // return data that setModelData should store.
protected slots:
virtual void onClicked() = 0; // implemented by sub classes
}
To copy to clipboard, switch view to plain text mode
EditorButton::setEditorData() could also set the button's text, but you can also do that in the delegate.
It could also be subclass specific, i.e. using QString as the type for file names. depends on where you want to know about which class
Cheers,
_
Bookmarks