[Qt-interest] Adding the check box and widget to the zeroth column in QTreeWidget
Andre Somers
andre at familiesomers.nl
Fri Apr 22 08:41:58 CEST 2011
Op 22-4-2011 6:22, srikanth bemineni schreef:
> Hi,
>
> I have a tree view and and first column needs to have a check box. I
> also need to add a widget to the same column
> Here is my sample code
>
>
> QTreeWidgetItem* item = new QTreeWidgetItem(myTreeWidget);
> item->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
> QLabel label = new QLabel("Hello") ;
> //Here I am adding only a label but in my code I am adding some
> composite widget which is made up of multiple labels and QTextboxes
> for word wraping
> myTreeWidget->setItemWidget(item , 0 , label);
>
> In this case I do get a check box but i am not able to click the check
> boxes. It doesn't even generate the itemchanged() signal from the tree
> widget.
>
> How can I put my widget in the 0 columns and as well as use the
> functionality of the checkbox in the QTreeWidget.
>
>
> The alternative that I am thinking of , if Qtreewidget checkbox is not
> an option and is a limitation in the above mentioned scenario
>
> I will keep a Qcheckbox in my widget and generate the state change
> from it. But I would really like to get feed back on this before I go
> ahead changes which requires requires modifying a lot of code at
> multiple places.
>
> Thank you in advance
Qt is perfectly capable of adding a checkbox in an item view like you
are trying to do, so something else is wrong. I don't use QTreeWidget
much myself, so at first glance I don't the problem, but I would
recommend you try to get it to work with the normal view classes, and
not use widgets in your items if you can avoid it.
André
More information about the Qt-interest-old
mailing list