[Qt-interest] Adding the check box and widget to the zeroth column in QTreeWidget
Malyushytsky, Alex
alex at wai.com
Sat Apr 23 00:54:11 CEST 2011
I am not sure where the problem is.
If you set custom widget for a column it covers entire area of the column for this item.
So nothing, including text, checkboxes, etc provided by QTreeWidgetItem is visible.
In this case if you want any other control (checkbox) you have to add it to your custom widget.
>> I cannot convince these people to go ahead with changing the whole code right now.
QTreeWidget is more than QTreeView. Using it makes coding simpler and faster. This makes QTreeWidget mostly always preferable solution unless your data size or any other factor requires you to use more flexible QTreeView.
In any case I would advice not to refer to people you work with as "these people". As for me this sounds rude.
Alex
From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of srikanth bemineni
Sent: Friday, April 22, 2011 6:19 AM
To: Andre Somers
Cc: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] Adding the check box and widget to the zeroth column in QTreeWidget
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
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”
“Please consider our environment before printing this email.”
More information about the Qt-interest-old
mailing list