I'm writing a simple note-taking app.
On the left is a QTreeWidget to select a note; on the right is a QTextEdit to edit it.
Items in the QTreeWidget are TreeWidgetItem's :
class TreeWidgetItem: public QTextDocument, public QTreeWidgetItem
Everything works fine but now I want to copy/paste notes.
My problem concerns cloning a TreeWidgetItem.
I wanted to write a copy constructor:
TreeWidgetItem(const TreeWidgetItem &other) : TreeWidgetItem(other), QTreeWidgetItem(other){...}
but QTextDocument does not have a public copy constructor so I thought I'd write a clone method to use QTextDocument::clone() instead:
TreeWidgetItem *TreeWidgetItem::clone ( ){
TreeWidgetItem *clone = (TreeWidgetItem *)this->QTextDocument::clone(); //note nasty cast
...fix up TreeWidget stuff ...
return clone;
}
but then the QTreeWidgetItem default constructor would never get called.
I could get round the problem by having a QTextDocument as a field in TreeWidgetItem rather than inheriting directly but that would involve a lot of re-writing.
Does anyone have an elegant solution please?.
Bob.
Bookmarks