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.

4
  • 3
    Google "pyqt delegate example", found: saltycrane.com/blog/2008/01/pyqt4-qitemdelegate-example-with Commented Jan 8, 2016 at 9:54
  • This example is for painting a widget, not for composing widgets. Commented Jan 8, 2016 at 17:29
  • I'm not sure what you mean. What's the difference according to you ? Commented Jan 8, 2016 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. Commented Jan 9, 2016 at 3:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
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
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!!
Thank you! One always must remember about security in this web stuff, and I forgot:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.