0

Hey. I'm working on a project, porting a software from Qt3 to Qt4. Its in PyQt, but I'm okay taking answers as if I was working with C++ and the originals Qt4 libraries.

In the old code, a ListView with checkboxes are used. When trying to find the eqvalient for Qt4, nokia advise to not use Q3CheckListItem in new code, but there are no links to Qt4 eqvalient.

The solution seems to be having a delegate, and set that on the items. Like this myListView.setDelegate(delegate). The delegate is supposed to make the checkboxes and so on, but I can't find any examples or tutorials on this.

Thanks

  • I don't think it's possible without delegates and a custom model capable of holding boolean values. I have some code that does that, but in Python and for a QTableView. Can post it as an answer if you're interested. – Sergei Tachenov Feb 08 '11 at 16:32
  • Thanks, its python that I write in :) –  Feb 08 '11 at 16:56
  • (BTW, use @name, possibly shortened, when replying to someone so they will get notified), I have missed the part about PyQt. Looks like I was wrong about having to use delegates, though, so I don't think posting my code would make any sense here. I must warn you, however, that models written in Python are pretty slow because of a lot of marshaling/unmarshaling between Python and C++. Depends on how much items you have in your model, though. – Sergei Tachenov Feb 08 '11 at 18:48

1 Answers1

2

You do not need delegates in order to have checkable items in your view, you just need to implement your model accordingly. Return Qt.ItemIsUserCheckable in the implementation of .flags(), and handle Qt.CheckStateRole in the implementations of .data() and .setData() (example).