PDA

View Full Version : Why isnt MyItemDelegate working??? please help!



Slewman
23rd February 2010, 23:00
so i am trying to get an icon to fill up the space of a QTableWidgetItem. so i subclassed the ItemDelegate and set it to my QTableWidget, but still, the icons wont fill out the item in the table.

here is my code... below is what i have at the top of my *.cpp file



class MyItemDelegate: public QItemDelegate
{
public:
MyItemDelegate(QObject* pParent = 0) : QItemDelegate(pParent)
{
std::cout<<"INSIDE DELEGATE PAINT~~~~~~~~~~~~~~~~~~"<<std::endl;
}
void MyItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
drawBackground(painter, option, index);
drawDecoration(painter, option, option.rect, icon.pixmap(option.rect.size()));
drawFocus(painter, option, option.rect);
std::cout<<"INSIDE DELEGATE PAINT"<<std::endl;
}
};


and here is where i am setting the delegate to my table



mThumbArea->setItemDelegate(new MyItemDelegate(mThumbArea));


here is where i add the icon to the table



QTableWidgetItem *newItemImage = new QTableWidgetItem(QIcon(filename),"");
mThumbArea->setItem(0,0,newItemImage);


filename is valid, and the item is successfully added to the table, its just that the icon is much too small... what is happening!!!

been_1990
24th February 2010, 01:20
QIcon.pixmap() says:

Returns a pixmap with the requested size, mode, and state, generating one if necessary. The pixmap might be smaller than requested, but never larger.
Maybe go:

icon.pixmap(QSize(50,50));
Just to see if it get's bigger?

Slewman
24th February 2010, 14:03
No that didnt change the size. the icon is still scaled down and shoved to the left side of the item box.

Slewman
24th February 2010, 15:59
anyone have any ideas? ive been banging my head against my computer all day yesterday and today... i cant seem to figure out what the problem is!

Slewman
24th February 2010, 19:22
do i have to continuously set my item delegate whenever i am trying to add an item to my table or do i only need to set the item delegate once in the constructor of my class... seriously... i dont know what im doing wrong... trying EVERYTHING!