{
QString title
= index.
data(Qt
::DisplayRole).
toString();
QString description
= index.
data(Qt
::UserRole).
toString();
int imageSpace = 10;
//TITLE
r = option.rect.adjusted(imageSpace, 0, -10, -30);
painter
->setFont
(QFont( "Lucida Grande",
12,
QFont::Normal));
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignBottom|Qt::AlignLeft, title, &r);
//DESCRIPTION
r = option.rect.adjusted(imageSpace, 30, -10, 0);
painter
->setFont
(QFont("Lucida Grande",
10,
QFont::Normal));
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignLeft, description, &r);
}
void AlertListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QRect r = option.rect;
QString title = index.data(Qt::DisplayRole).toString();
QString description = index.data(Qt::UserRole).toString();
int imageSpace = 10;
//TITLE
r = option.rect.adjusted(imageSpace, 0, -10, -30);
painter->setFont(QFont( "Lucida Grande", 12, QFont::Normal));
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignBottom|Qt::AlignLeft, title, &r);
//DESCRIPTION
r = option.rect.adjusted(imageSpace, 30, -10, 0);
painter->setFont(QFont("Lucida Grande", 10, QFont::Normal));
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignLeft, description, &r);
}
To copy to clipboard, switch view to plain text mode
myListWidget->setItemDelegate(new AlertListDelegate(myListWidget));
item->setData(Qt::DisplayRole, "Title");
item->setData(Qt::UserRole, "Description");
myListWidget->addItem(item);
item2->setData(Qt::DisplayRole, "Title2");
item2->setData(Qt::UserRole, "Description2");
myListWidget->addItem(item2);
item3->setData(Qt::DisplayRole, "Title3");
item3->setData(Qt::UserRole, "Description3");
myListWidget->addItem(item3);
QListWidget* myListWidget = new QListWidget();
myListWidget->setItemDelegate(new AlertListDelegate(myListWidget));
QListWidgetItem *item = new QListWidgetItem();
item->setData(Qt::DisplayRole, "Title");
item->setData(Qt::UserRole, "Description");
myListWidget->addItem(item);
QListWidgetItem *item2 = new QListWidgetItem();
item2->setData(Qt::DisplayRole, "Title2");
item2->setData(Qt::UserRole, "Description2");
myListWidget->addItem(item2);
QListWidgetItem *item3 = new QListWidgetItem();
item3->setData(Qt::DisplayRole, "Title3");
item3->setData(Qt::UserRole, "Description3");
myListWidget->addItem(item3);
To copy to clipboard, switch view to plain text mode
Bookmarks