QListWideget and QListWidgetItem



  • I need to customize the way the QListWidgetItem is painted. I found QStyledItemDelegate and I was wandering if QStyledItemDelegate is the way to go or I can customize the item trough an xml layout like in android. Thanks in advance.



  • The answer depends on what you like to change. If you want to change only colors (like background, text color) it can be done via properties of the items. If you want a complete custom drawing (like gradients, or whatever), you must use a delegate.



  • AFAIK there is no way to use delegates with QListWidget (or QTableWidget / QTreeWidget).
    You can only customize your items with the properties QListWidgetItem has.
    If you want to do more, you'll have to use QListView with either QStandardItemModel or your own implementation of QAbstractItemModel. Then you can use QAbstractItemView::setItemDelegate()



  • [quote author="Gerolf" date="1351064579"]The answer depends on what you like to change. If you want to change only colors (like background, text color) it can be done via properties of the items. If you want a complete custom drawing (like gradients, or whatever), you must use a delegate.[/quote]

    thanks. I have to draw an icon and a text. Text should be vertical aligned with the icon. Any idea? I have alerady a QStyledItemDelegate, I was just wandering what is better



  • Icons can be added as decoration role, the you have icon and text side by side (typically icon on the left).
    Otherwise the delegate has a paint method. Overwrite it and do, what is needed there.

    @Mr.Universe: QListWidget is a QListView and you can use delegates for them, just not own models.



  • [quote author="Gerolf" date="1351065505"]

    @Mr.Universe: QListWidget is a QListView and you can use delegates for them, just not own models.[/quote]

    oops, you're right. Never tried that before...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.