The item delegate:
{
Q_OBJECT
public:
MyItemDelegate();
~MyItemDelegate();
private:
};
class MyItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
MyItemDelegate();
~MyItemDelegate();
virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
private:
QSize mSize;
};
To copy to clipboard, switch view to plain text mode
The item:
{
public:
enum DataRole
{
TextRole = Qt::UserRole + 1,
//other roles
};
MyTreeWidgetItem(... );
~MyTreeWidgetItem();
};
class MyTreeWidgetItem : public QTreeWidgetItem
{
public:
enum DataRole
{
TextRole = Qt::UserRole + 1,
//other roles
};
MyTreeWidgetItem(... );
~MyTreeWidgetItem();
QVariant data( int role )const;
};
To copy to clipboard, switch view to plain text mode
The paint method should be something like:
{
QString text
= model
->data
(index, MyTreeWidgetItem
::TextRole).
toString();
//here draw the item and the expand handle
//BTW - you should keep a refernece to it's rect for when it is clicked
}
This is a basic impl. You can add things to it according to your needs.
void MyItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
const QAbstractItemModel* model = index.model();
QString text = model->data(index, MyTreeWidgetItem::TextRole).toString();
//here draw the item and the expand handle
//BTW - you should keep a refernece to it's rect for when it is clicked
}
This is a basic impl. You can add things to it according to your needs.
To copy to clipboard, switch view to plain text mode
Bookmarks