PDA

View Full Version : QListWidget icons on right



bwnicewo
2nd February 2012, 21:00
I'm trying to make it so that a QListWidget will have icons to the far right and text justified to the right as well. I know ABOUT delegates but I have no idea how to make custom delegates for them, I have also heard of setting the layout direction (e.g. Qt::RightToLeft, etc.) is there a simpler way to do this, if at all?

norobro
4th February 2012, 01:22
For text alignment see: QListWidgetItem::setTextAlignment()


To right align the icons you can subclass QStyledItemDelegate and override the paint() method. Something like this should work:
void myDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{
QStyleOptionViewItem myOpt(option);
myOpt.decorationPosition = QStyleOptionViewItem::Right;
QStyledItemDelegate::paint(painter, myOpt, index);
}