[Qt-interest] Adding the check box and widget to the zeroth column in QTreeWidget

srikanth bemineni bemineni.srikanth at gmail.com
Fri Apr 22 15:19:28 CEST 2011


Hi,

I do agree with you. I can add a check box, if I only use the
QTreeWidgetItem setText feature.The below sample code works absolutely fine,
It creates the checkbox in the zeroth column and I am able to check and
uncheck it.

QTreeWidgetItem* item = new QTreeWidgetItem(myTreeWidget);
 item->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
item->setText(0,"Hello");

 I will not be able to add my own custom widget to the 0 column. I have to
only use the text ability of the cell.

Anybody facing this problem. The reason I cannot change it to a QTreeView is
that the whole project is already using QTreeWidget and they are not relying
on writing the code in a view/model controller architecture. I cannot
convince these people to go ahead with changing the whole code right now.

With regards
Srikanth Bemineni

On Fri, Apr 22, 2011 at 1:41 AM, Andre Somers <andre at familiesomers.nl>wrote:

> 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é
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110422/e537d26e/attachment.html 


More information about the Qt-interest-old mailing list