Results 1 to 2 of 2

Thread: QListWidget icons on right

  1. #1
    Join Date
    Jan 2012
    Qt products

    Default QListWidget icons on right

    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?

  2. #2
    Join Date
    Feb 2008
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5

    Default Re: QListWidget icons on right

    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:
    Qt Code:
    1. void myDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{
    2. QStyleOptionViewItem myOpt(option);
    3. myOpt.decorationPosition = QStyleOptionViewItem::Right;
    4. QStyledItemDelegate::paint(painter, myOpt, index);
    5. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 1st April 2011, 09:32
  2. Where have all the icons gone?
    By gib in forum Qt Programming
    Replies: 7
    Last Post: 6th September 2010, 08:19
  3. QListWidget doesn't show icons
    By franco.amato in forum Qt Programming
    Replies: 8
    Last Post: 16th March 2010, 14:15
  4. Replies: 1
    Last Post: 22nd February 2010, 10:53
  5. Icons in a QListWidget
    By LuHe in forum Qt Tools
    Replies: 10
    Last Post: 30th January 2010, 04:19

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.