please post the code. I'm near to the solution. A rectangle is showing, but if I set a picture as cell content, I can't see the border of the drawn rectangle .
For drawing the rectangle, I wrote my own itemdelegate class and rewrote the paint event like this:
QRect rect1
= option.
rect;
rect1.setHeight(rect1.height()+1);
rect1.setWidth(rect1.width()+1);
if(option.
state & QStyle::State_Selected) {
painter->setPen(Qt::red);
painter->drawRect(rect1);
}
}
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{
QItemDelegate::paint(painter,option,index);
QRect rect1 = option.rect;
rect1.setHeight(rect1.height()+1);
rect1.setWidth(rect1.width()+1);
if(option.state & QStyle::State_Selected)
{
painter->setPen(Qt::red);
painter->drawRect(rect1);
}
}
To copy to clipboard, switch view to plain text mode
Added after 44 minutes:
as you said: post to get help and get the solution by yourself some minutes later.
My Solution: I used the paint event of the previous post. Than I set the images as icons an add it to the cell:
ico.addPixmap(pix);
iconitem->setIcon(ico);
ui->tableWidgetZusatzaufnahme->setIconSize(size);
ui->tableWidgetZusatzaufnahme->setItem(row,column,iconitem);
QPixmap pix(myfile);
QIcon ico;
ico.addPixmap(pix);
QTableWidgetItem *iconitem = new QTableWidgetItem;
iconitem->setIcon(ico);
ui->tableWidgetZusatzaufnahme->setIconSize(size);
ui->tableWidgetZusatzaufnahme->setItem(row,column,iconitem);
To copy to clipboard, switch view to plain text mode
Bookmarks