Using a custom QStyledItemDelegate like this
class CustomListWidgetItemDelegate : public QStyledItemDelegate {
public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override {
painter->save();
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.highlight());
else if (option.state & QStyle::State_MouseOver)
painter->fillRect(option.rect, option.palette.highlight());
//left aligned
if(index.data(Qt::DisplayRole).isValid()) {
QString text = index.data(Qt::DisplayRole).toString();
painter->drawText(QPoint(option.rect.left() + 5, option.rect.bottom()-5), text);
}
//right aligned
if(index.data(Qt::UserRole).isValid()) {
QString text = index.data(Qt::UserRole).toString();
int textwidth = painter->fontMetrics().boundingRect(text).width();
painter->drawText(QPoint(option.rect.right() - textwidth - 5, option.rect.bottom()-5), text);;
}
//fixed
if(index.data(Qt::UserRole + 1).isValid()) {
QString text = index.data(Qt::UserRole + 1).toString();
painter->drawText(QPoint(200, option.rect.bottom()-5), text);;
}
painter->restore();
}
};
Now that theres more than one text, the other texts are stored in UserRoles
//install delegate on the ListWidget
ui->listWidget->setItemDelegate(new CustomListWidgetItemDelegate);
QListWidgetItem * item = nullptr;
for(int i = 0; i < 5; i++) {
item = new QListWidgetItem("ListItem");
item->setData(Qt::UserRole, "Yep");
item->setData(Qt::UserRole + 1, "Maybe");
ui->listWidget->addItem(item);
}