21 const QStyleOptionViewItem& option,
22 const QModelIndex& index
25 if (option.state & QStyle::State_MouseOver) {
26 QRect rect = option.rect;
27 QLinearGradient gradient(0, 0, rect.width(), rect.height());
29 gradient.setColorAt(0, Qt::white);
30 gradient.setColorAt(0.5, Qt::blue);
31 gradient.setColorAt(1, Qt::green);
32 pPainter->setBrush(gradient);
33 pPainter->drawRect(rect);
35 QStyledItemDelegate::paint(pPainter, option, index);
38 QSize
sizeHint(
const QStyleOptionViewItem& option,
42 return QSize(option.rect.width(), 55);
47 int main(
int argc,
char *argv[])
49 QApplication app(argc, argv);
50 QStringListModel model;
51 model.setStringList(QStringList() <<
"Item1" <<
"Item2" <<
"Item3");
54 listView.setModel(&model);
56 listView.viewport()->setAttribute(Qt::WA_Hover);
SimpleDelegate(QObject *pobj=0)
void paint(QPainter *pPainter, const QStyleOptionViewItem &option, const QModelIndex &index) const
int main(int argc, char **argv)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const