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>
{
public:
ColumnIconDelegate
(QObject *parent
= 0);
};
#endif // 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
To copy to clipboard, switch view to plain text mode
ColumnIconDelegate.cpp
#include "ColumnIconDelegate.h"
/*----------------------------------------------------------------------------*/
ColumnIconDelegate
::ColumnIconDelegate(QObject *parent
){
//qDebug()() << "ColumnDateDelegate Costruttore";
}
/*----------------------------------------------------------------------------*/
void ColumnIconDelegate
::paint(QPainter *painter,
{
IconCalendar.load(":sottomenu/images/calendar-empty.png", "PNG", Qt::AutoColor);
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(),pixIcona,pixIcona,IconCalendar);
drawDisplay(painter, myOption, myOption.rect, "");
drawFocus(painter, myOption, myOption.rect);
}
#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(),pixIcona,pixIcona,IconCalendar);
drawDisplay(painter, myOption, myOption.rect, "");
drawFocus(painter, myOption, myOption.rect);
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks