2 Attachment(s)
QItemDelegate and QStyle::State_Selected
Hi to all,
I'm looking for a solution to my QItemDelegate applied to a QTreeView:
ColumnIconDelegate.h
Code:
#ifndef COLUMNICONDELEGATE_H
#define COLUMNICONDELEGATE_H
#include <QtGui>
{
public:
ColumnIconDelegate
(QObject *parent
= 0);
};
#endif // COLUMNICONDELEGATE_H
ColumnIconDelegate.cpp
Code:
#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);
}
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
Re: QItemDelegate and QStyle::State_Selected
You have to call drawDisplay and drawFocus fist, then paint your icon. Right now you icon is covered by the later drawn blue background!
Re: QItemDelegate and QStyle::State_Selected
Quote:
Originally Posted by
Lykurg
You have to call drawDisplay and drawFocus fist, then paint your icon. Right now you icon is covered by the later drawn blue background!
Ops, thanks!
Re: QItemDelegate and QStyle::State_Selected
You can also simply override QItemDelegate::drawDecoration if you want to change only the icon.