cydside
25th July 2010, 17:09
Hi to all,
I'm looking for a solution to my QItemDelegate applied to a QTreeView:
ColumnIconDelegate.h
#ifndef COLUMNICONDELEGATE_H
#define COLUMNICONDELEGATE_H
#include <QtGui>
class ColumnIconDelegate: public QItemDelegate
{
public:
ColumnIconDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
};
#endif // COLUMNICONDELEGATE_H
ColumnIconDelegate.cpp
#include "ColumnIconDelegate.h"
/*----------------------------------------------------------------------------*/
ColumnIconDelegate::ColumnIconDelegate(QObject *parent)
: QItemDelegate(parent)
{
//qDebug()() << "ColumnDateDelegate Costruttore";
}
/*----------------------------------------------------------------------------*/
void ColumnIconDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QPixmap IconCalendar(48, 48);
IconCalendar.load(":sottomenu/images/calendar-empty.png", "PNG", Qt::AutoColor);
QStyleOptionViewItem myOption = option;
myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
int pixIcona;
if (myOption.rect.height() > 48) pixIcona = 48;
else pixIcona = (myOption.rect.height());
painter->drawPixmap(myOption.rect.x(),myOption.rect.y(),pix Icona,pixIcona,IconCalendar);
drawDisplay(painter, myOption, myOption.rect, "");
drawFocus(painter, myOption, myOption.rect);
}
it shows the icon when the item is NOT selected (see picture Before_Click.png) but it disappears after the click (see picture After_Click.png),so what are I missing?
thanks
I'm looking for a solution to my QItemDelegate applied to a QTreeView:
ColumnIconDelegate.h
#ifndef COLUMNICONDELEGATE_H
#define COLUMNICONDELEGATE_H
#include <QtGui>
class ColumnIconDelegate: public QItemDelegate
{
public:
ColumnIconDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
};
#endif // COLUMNICONDELEGATE_H
ColumnIconDelegate.cpp
#include "ColumnIconDelegate.h"
/*----------------------------------------------------------------------------*/
ColumnIconDelegate::ColumnIconDelegate(QObject *parent)
: QItemDelegate(parent)
{
//qDebug()() << "ColumnDateDelegate Costruttore";
}
/*----------------------------------------------------------------------------*/
void ColumnIconDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QPixmap IconCalendar(48, 48);
IconCalendar.load(":sottomenu/images/calendar-empty.png", "PNG", Qt::AutoColor);
QStyleOptionViewItem myOption = option;
myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
int pixIcona;
if (myOption.rect.height() > 48) pixIcona = 48;
else pixIcona = (myOption.rect.height());
painter->drawPixmap(myOption.rect.x(),myOption.rect.y(),pix Icona,pixIcona,IconCalendar);
drawDisplay(painter, myOption, myOption.rect, "");
drawFocus(painter, myOption, myOption.rect);
}
it shows the icon when the item is NOT selected (see picture Before_Click.png) but it disappears after the click (see picture After_Click.png),so what are I missing?
thanks