#include <QItemDelegate>
#include <QModelIndex>
#include <QObject>
#include <QSize>
#include <QSpinBox>
{
Q_OBJECT
public:
TreeViewItemDelegate
(QObject *parent
= 0);
};
#include <QItemDelegate>
#include <QModelIndex>
#include <QObject>
#include <QSize>
#include <QSpinBox>
class TreeViewItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
TreeViewItemDelegate(QObject *parent = 0);
void paint( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const;
};
To copy to clipboard, switch view to plain text mode
.cpp file
TreeViewItemDelegate
::TreeViewItemDelegate(QObject *parent
){
}
void TreeViewItemDelegate
::paint( QPainter * painter,
{
QString contactURI
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
QIcon icon
= qvariant_cast<QIcon>
(index.
model()->data
(index, Qt
::DecorationRole));
QIcon icon2
= qvariant_cast<QIcon>
(index.
model()->data
(index, Qt
::UserRole+5));
QPixmap iconPixmap
= icon.
pixmap(option.
decorationSize);
QPixmap iconPixmap2
= icon2.
pixmap(option.
decorationSize);
myoption.displayAlignment = Qt::AlignCenter;
myoption2.decorationAlignment = Qt::AlignLeft;
myoption3.decorationAlignment = Qt::AlignRight;
drawBackground(painter, myoption, index);
drawDecoration(painter, myoption, myoption2.rect, iconPixmap);
drawDisplay(painter,myoption, myoption.rect, contactURI);
drawDecoration(painter, myoption, myoption3.rect, iconPixmap2);
drawFocus(painter, myoption,myoption.rect);
}
TreeViewItemDelegate::TreeViewItemDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
void TreeViewItemDelegate ::paint( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
QString contactURI = index.model()->data(index, Qt::DisplayRole).toString();
QIcon icon = qvariant_cast<QIcon>(index.model()->data(index, Qt::DecorationRole));
QIcon icon2 = qvariant_cast<QIcon>(index.model()->data(index, Qt::UserRole+5));
QPixmap iconPixmap = icon.pixmap(option.decorationSize);
QPixmap iconPixmap2 = icon2.pixmap(option.decorationSize);
QStyleOptionViewItem myoption = option;
QStyleOptionViewItem myoption2 = option;
QStyleOptionViewItem myoption3 = option;
myoption.displayAlignment = Qt::AlignCenter;
myoption2.decorationAlignment = Qt::AlignLeft;
myoption3.decorationAlignment = Qt::AlignRight;
drawBackground(painter, myoption, index);
drawDecoration(painter, myoption, myoption2.rect, iconPixmap);
drawDisplay(painter,myoption, myoption.rect, contactURI);
drawDecoration(painter, myoption, myoption3.rect, iconPixmap2);
drawFocus(painter, myoption,myoption.rect);
}
To copy to clipboard, switch view to plain text mode
There is on problem that only one icon is displaying. I know i am doing something wrong, so can anyone help me to correct this code to display both icon??
Bookmarks