Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Does QListView support an owner draw feature?



  • I am using QListView to display a list of icons. For each icon item, I want to draw the icon by myself. Does QListView support a owner draw feature or can I override the draw event so that whenever an item is to be drawed, I can get notification and draw by myself instead of letting Qt to do that?

    Thanks


  • Qt Champions 2017

    You need to have your own delegate. When you want to have custom drawing you need to write you own delegate. Please look at writing CustomDelegate.


  • Lifetime Qt Champion

    Hi,

    To add to Dheerendra, you are looking for the QStyledItemDelegate class



  • OK. Thank you. It seems that I need to override QStyledItemDelegate::paint function, to draw the following thing for an item:

    1. An icon
    2. A text
    3. A checkbox

    I have found the way of drawing checkbox. However, which event will be fired when the user clicking the checkbox? Since the checkbox is drawed by myself, how can an event be fired properly when user click it?


Log in to reply