I'm new to PyQt and I have to work on an application which use it. For the moment, I don't have any problem, but I'm stuck on something. I have to create a "ComboBox with its items checkable, like a CheckBox". This ComboBox should contain many image format, like "jpg", "exr" or "tga", and I will have to pick up the text of the checked option and put it in a variable. The problem is that I can't find a thing about making items checkable using a ComboBox (if you know how to, It would gladly help me !)
Since I can't do it with a ComboBox, maybe I can do it with a QList I thought, but I can't find anything either which is understandable for a beginner like me. I have read stuff about flags and "Qt.ItemIsUserCheckable" but I don't know how to use it in a easy way :(
Can you help me ? Thanks !
PyQt version : 4.4.3
Python version : 2.6
You can do this using the model->view framework, but it means implementing a custom model to support checkable data.
You create a custom model by subclassing QAbstractItemModel. This presents an API to the QComboBox for accessing the underlying data. Off the top of my head I think you'll need to implement the flags method to indicate that you support ItemIsUserCheckable for the indexes you want to be able to check. You'll also need to implement data() which reports back the data state from your underlying data, and setData() which accept input from the QComboBox and changes the underlying data.
You then set this as the model for the QComboBox using setModel().
This isn't really beginner stuff, but the model->view framework in Qt is one of it's most important and valuable features and well worth getting to grips with.
How to simply create a list of CheckBox which has a dropdown list like a ComboBox with PyQt?