[Qt-interest] How to make a list of checkboxes
yogesh upreti
yogesh.upreti at gmail.com
Mon May 31 10:04:34 CEST 2010
Hallo Andre,
Thanks for reply. Can I find an example anywhere.
I don't want to read the whole Model/View Architecture documentation.. :D
-Yogi
Message: 7
Date: Mon, 31 May 2010 09:30:42 +0200
From: Andre Somers <andre at familiesomers.nl>
Subject: Re: [Qt-interest] How to make a list of checkboxes
To: qt-interest at trolltech.com
Message-ID: <4C0365A2.70903 at familiesomers.nl>
Content-Type: text/plain; charset="iso-8859-1"
Op 31-5-2010 8:37, yogesh upreti schreef:
> Hallo Group,
> I have seen this question being ask a lot of times in the group, but
> all the discussion I saw in mail archeive talks about QCheckListItem
> which is ( I think) not available in Qt 4.6, as I couldn't find any
> reference in documentation.
> So can someone please tell me how to make checkbox in QListView or
> QListWidget? and also how to access checking and unchecking of Item.
When using QListView, you need to provide your own model (derived
directly or indirectly from QAbstractItemModel). To make an item
checkable, you need to return 1) the correct combination of flags from
QAbstractItemModel::flags(), 2) make QAbstractItemModel::data() return
appropriate data for Qt::CheckStateRole and 3) to store the checks,
implement setData() for the same role. This is also where you can
"access the checking and unchecking" of the item. You can, in your
QAbstractItemModel subclass, create a signal that you emit if the
checkstate is toggled.
> I tried it using QListWidgetItem with
> item->setFlags(Qt::ItemIsUserCheckable), but doing this is changing my
> item to somehow disabled item and not chowing any checkboxes.
>
Obviously. The flags is plural. That is: it is a combination of multiple
flags that control different aspects of the look and feel of the item.
If you only set Qt::ItemIsUserCheckable, you are not setting
Qt::ItemIsEnabled... You need to set the correct *combination* of flags.
You can do that by bitwise or-ing them together. Read the QFlags
documentation for details.
Also, don't forget to set the actual value of the checkbox using
QListWidgetItem::setData(Qt::CheckStateRole, QVariant(Qt::Checked));
Andr?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100531/4ee13b8d/attachment.html
More information about the Qt-interest-old
mailing list