[Qt-interest] Adding multiple checkboxes to a QTreeView with QFileSystemModel
Sven Grunewaldt
strayer at olle-orks.org
Thu Jul 15 13:04:15 CEST 2010
Hey Andre,
thanks for your reply. I tried creating a proxy model but after some
days of fiddling around I have to give up, I don't know how to code this
properly...
I uploaded my current source code to http://pastebin.ca/1900964
Maybe someone can look into it and give me directions.
What my code should do: Prepend three columns containing the text
"Checkbox N" to the existing columns.
Sadly it has several problems:
- only the first column of the source model is shown after my three columns
- there are no more children to the items
Maybe this really can't be done... then I'd "recreate" QFileSystemModel
with a completely new QAbstractItemModel. Though I think that a a proxy
model would be a better way...
Regards,
Sven Grunewaldt
Am 12.07.2010 21:37, schrieb Andre Somers:
> Op 12-7-2010 14:57, Sven Grunewaldt schreef:
>> Hi,
>>
>> I need multiple (currently 3, maybe more in the future) Checkboxes in
>> front of the first column in a QTreeView. The view is populated by a
>> QFileSystemModel.
>>
>> All the examples I can find are about adding ONE checkbox which can be
>> achieved by setting the checkable-flag or so. Sadly this doesn't work
>> for more than one checkbox...
>>
>> I tried QItemDelegate but I don't understand how I should use a delegate
>> to add multiple checkboxes in ONE column, I guess this class is not made
>> for stuff like this.
>> After that I tried subclassing QFileSystemModel and implementing my own
>> data() function which calls the parent function when the column is
>> higher than 0, but this leads to access violations and other funny stuff...
>>
>> How can I achieve this? I'm at a total loss right now...
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
> You have two issues to address: the first is to actually show the check
> boxes, but you will also have to think about how you are going to store
> the check state.
>
> The ultimate solution depends on your exact needs. Would it be
> acceptable for you to have the checkboxes in separate columns? Or do you
> need them all in the first column?
> If separate columns are acceptable, then I think I would prefer using a
> method where you use a proxy model to add columns to an existing model,
> and keep track of the checkstate of each of the items. That would be the
> simplest option by far.
>
> However, if you do need to have all three checkboxes in the same column,
> you have no option than to use a delegate. Drawing the checkboxes can be
> done using the methods supplied by QStyle. Look at how
> QStyledItemDelegate is implemented for inspiration. It is not trivial!
> You also need to take care to handle mouse clicks on the items
> (QAbstractItemDelegate provides a method for this), as well as think of
> a way to store the state of the items.
>
> André
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list