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
{
public:
{
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;
}
};
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;
}
};
To copy to clipboard, switch view to plain text mode
and here is where i am setting the delegate to my table
mThumbArea->setItemDelegate(new MyItemDelegate(mThumbArea));
mThumbArea->setItemDelegate(new MyItemDelegate(mThumbArea));
To copy to clipboard, switch view to plain text mode
here is where i add the icon to the table
mThumbArea->setItem(0,0,newItemImage);
QTableWidgetItem *newItemImage = new QTableWidgetItem(QIcon(filename),"");
mThumbArea->setItem(0,0,newItemImage);
To copy to clipboard, switch view to plain text mode
filename is valid, and the item is successfully added to the table, its just that the icon is much too small... what is happening!!!
Bookmarks