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!!!
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!!!