cellDelegate *cDO = new cellDelegate();
tableView1->setItemDelegate(cDO);
cellDelegate *cDO = new cellDelegate();
tableView1->setItemDelegate(cDO);
To copy to clipboard, switch view to plain text mode
{
painter->save();
int mTextLeftOffset = 10,mIconSize=30,mIconTopOffset=20,mTextTopOffset=0;
// QIcon icon(":/arrowBig.png");
font.setPointSize(10);
text=qvariant_cast<QString>(index.data(Qt::DisplayRole));
QIcon icon
= qvariant_cast<QIcon>
(index.
data(Qt
::DecorationRole));
QRect textRect
= option.
rect;
QRect iconRect
= option.
rect;
int displayables = 0;
if (!icon.isNull())
icon.
paint(painter,
QRect(0,
0,
16,
16), Qt
::AlignVCenter|Qt
::AlignRight);
QSize iconsize
= icon.
actualSize(option.
decorationSize);
iconRect.setTop (iconRect.top() + mIconTopOffset); //device-dependent?
iconRect.setBottom (iconRect.top() + mIconSize);
iconRect.setRight (iconRect.left() + iconsize.width());
textRect.setLeft (iconRect.right() + (iconsize.width()/4) * 3);
textRect.setRight (textRect.left() + fm.width(text));
textRect.setTop (textRect.top() + ((option.rect.height() - fm.height()) / 2) + mTextTopOffset); //device-dependent?
if (!icon.isNull())
//painter->drawPixmap(iconRect.center(),icon.pixmap(mIconSize, mIconSize));
painter
->drawPixmap
(QPoint(iconRect.
right()+iconsize.
width()/2+2,iconRect.
top()+iconsize.
height()/2+3),icon.
pixmap(iconsize.
width(),iconsize.
height()));
if (displayables == 0 || displayables == 2 || !(icon.isNull()) )
{
qDebug()<<"at 109";
painter->setFont(font);
painter->drawText(textRect.left(),textRect.top()+10,text);
}
painter->restore();
}
void cellDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
painter->save();
QStandardItemModel columnName1 ;
int mTextLeftOffset = 10,mIconSize=30,mIconTopOffset=20,mTextTopOffset=0;
// QIcon icon(":/arrowBig.png");
QFont font = QApplication::font();
font.setPointSize(10);
QFontMetrics fm(font);
QString text = "";
text=qvariant_cast<QString>(index.data(Qt::DisplayRole));
QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
QRect textRect = option.rect;
QRect iconRect = option.rect;
int displayables = 0;
if (!icon.isNull())
icon.paint(painter, QRect(0, 0, 16, 16), Qt::AlignVCenter|Qt::AlignRight);
QSize iconsize = icon.actualSize(option.decorationSize);
iconRect.setTop (iconRect.top() + mIconTopOffset); //device-dependent?
iconRect.setBottom (iconRect.top() + mIconSize);
iconRect.setRight (iconRect.left() + iconsize.width());
textRect.setLeft (iconRect.right() + (iconsize.width()/4) * 3);
textRect.setRight (textRect.left() + fm.width(text));
textRect.setTop (textRect.top() + ((option.rect.height() - fm.height()) / 2) + mTextTopOffset); //device-dependent?
if (!icon.isNull())
//painter->drawPixmap(iconRect.center(),icon.pixmap(mIconSize, mIconSize));
painter->drawPixmap(QPoint(iconRect.right()+iconsize.width()/2+2,iconRect.top()+iconsize.height()/2+3),icon.pixmap(iconsize.width(),iconsize.height()));
if (displayables == 0 || displayables == 2 || !(icon.isNull()) )
{
qDebug()<<"at 109";
painter->setFont(font);
painter->drawText(textRect.left(),textRect.top()+10,text);
}
painter->restore();
}
To copy to clipboard, switch view to plain text mode
Bookmarks