0

I want to add a custom Widget to the QListView, i read already the SO thread about Delegates. QListView/QListWidget with custom items and custom item widgets

But how is this applied in pyqt? i couldn't find any example. Some articles show how to overwrite the paint function, which will only change the appearance but not add a widget as an item.

Community
  • 1
  • 1
user1767754
  • 23,311
  • 18
  • 141
  • 164
  • 3
    Google "pyqt delegate example", found: http://www.saltycrane.com/blog/2008/01/pyqt4-qitemdelegate-example-with/ – Mel Jan 08 '16 at 09:54
  • This example is for painting a widget, not for composing widgets. – user1767754 Jan 08 '16 at 17:29
  • I'm not sure what you mean. What's the difference according to you ? – Mel Jan 08 '16 at 17:55
  • It's not setting a widget for an element, its just changes how it appears, in the example you provided, it just changes the background color to red. But i would like to add per item, a custom widget, which can contain for example a qpusbutton or another widget. – user1767754 Jan 09 '16 at 03:58

1 Answers1

2

setCellWidget() if you can switch to QListWidget or QTableWidget add custom widget to QTableWidget cell

...or you can just spawn new Widget in a cell rectangle via delegate like I do here: delegate that edits bound python object properties

We used code like this to handle text, number, date, boolean, image, document file, coordinate, list properties etc of our domain objects.

Community
  • 1
  • 1
Maxim Popravko
  • 4,100
  • 3
  • 29
  • 43
  • Thanks for the Source Max, Is there a file missing ? You have the: ObjectDelegate, but it's not used anywhere, i would like to see how you use this within a list/table view. – user1767754 Jan 11 '16 at 02:48
  • I'd attach small sample tomorrow. Briefly, we used it with custom Q(Table|Tree|List)Widget, but you surely can do it with QTableView – Maxim Popravko Jan 12 '16 at 15:27
  • Thank you very much bro, i will look into those examples, that helps a lot! By the way, i somehow could see your other files on your driver share too, just make sure, no one sees your private stuff!! – user1767754 Jan 13 '16 at 07:16
  • Thank you! One always must remember about security in this web stuff, and I forgot:) – Maxim Popravko Jan 13 '16 at 16:56