PDA

View Full Version : QTreeWidget question



Mad Max
31st January 2006, 05:36
Hi,

I want to do like this (see the attached image). In qt3 it was solved simple use a QCheckViewItem class, but I can't find a similar solution in qt4 :confused: . Can anyone help me with this issue?

zlatko
31st January 2006, 09:48
im not remember QCheckViewItem in qt 3;)
It was QCheckListItem imho:) In qt4 it must be QTreeWidgetItem.

Mad Max
31st January 2006, 10:29
im not remember QCheckViewItem in qt 3;)
It was QCheckListItem imho:) In qt4 it must be QTreeWidgetItem.
Sorry, I made a mistake :) . I know about QTreeWidgetItem, but its behaviour does not allow me to design TreeView as illustrated in the attached image or probably, I have not found a correct way for it :confused: .

guilugi
31st January 2006, 11:36
Hello Man,

Since Qt 4.1, you have a new method in QTreeWidget to do this !


void QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget )

With this, you can set your checkboxes !

Guilugi.

fullmetalcoder
31st January 2006, 15:18
item delegates may work as well.
Reading the doc about Model/View architecture should help you a lot :p !

wysota
4th February 2006, 13:19
Use QTreeWidgetItem::setFlags() and add Qt::ItemIsUserCheckable flag to the flags for that item. You can then use QTreeWidgetItem::setCheckState() and QTreeWidgetItem::checkState() to manipulate the checkbox.

Mad Max
6th February 2006, 06:40
Use QTreeWidgetItem::setFlags() and add Qt::ItemIsUserCheckable flag to the flags for that item. You can then use QTreeWidgetItem::setCheckState() and QTreeWidgetItem::checkState() to manipulate the checkbox.
Thanks all for your help in search of the solution of my problem, but all suggested solutions do not allow to make as I want. It allow to create checkboxes AFTER display of tree only, but I need to have checkboxes which is leveled to a left border, BEFORE tree (such as in an attached image) .

wysota
6th February 2006, 09:53
It's a wild guess, but try setting those checkboxes for the last column for example and then move the last column before the first one. I doubt it'll work, but you might try it anyway.

You may have to subclass QTreeWidget to achieve the thing you want by reimplementing drawRow from the tree and drawing that checkbox yourself for every item, just be carefull not to break branching and indenting of items.

A simple solution would be to disable indentation completely, this way all checkboxes would form a vertical line like you want them to.

Reimplementing the delegate won't help, as it is only responsible for drawing the item itself and the item in a tree starts after the branching lines.

Mad Max
7th February 2006, 07:42
It's a wild guess, but try setting those checkboxes for the last column for example and then move the last column before the first one. I doubt it'll work, but you might try it anyway.

:) Probably... but in my case the row should present an united unit of information and I need to manipulate every row as a single whole. Unfortunately I can't to use this solution because theoretically I don't know number of columns.



You may have to subclass QTreeWidget to achieve the thing you want by reimplementing drawRow from the tree and drawing that checkbox yourself for every item, just be carefull not to break branching and indenting of items.

I tried this solution. Sure, I can draw a some region (similar to QCheckBox), I can catch a mouse button press on this region through mousePressEvent method, but this region will not be QCheckBox in point of fact. I cannot know a condition of this control. It would be desirable to find more comfortable solution for me and for users of course...


A simple solution would be to disable indentation completely, this way all checkboxes would form a vertical line like you want them to.

In this case I can't have a show of tree hierarchy :(

The some ambush around... :mad:

wysota
7th February 2006, 11:39
:) Probably... but in my case the row should present an united unit of information and I need to manipulate every row as a single whole. Unfortunately I can't to use this solution because theoretically I don't know number of columns.
So try that with a second column. I really doubt it works, but.... I just don't have better ideas :) You can always ask the Trolls if there is a solution for this.

Mad Max
16th February 2006, 19:49
It's a wild guess, but try setting those checkboxes for the last column for example and then move the last column before the first one. I doubt it'll work, but you might try it anyway.

I solved it thus. Slightly awry, but it work ok. Thanks all and special thanks to wysota for the active participation.

harpo
27th February 2006, 11:26
Hi,

Just to add to that question,

If I want to have functionality as such,
1. Upon checking/unchecking the parent QtreeWidgetItem checkbox,
->the children are corresponding changed to the parent item's checkbox state.

I've tried connecting the signal in the following way to address this, but it doesn't seem to work

QTreeWidgetItem *poRecord = new QTreeWidgetItem(ThisTreeWidget);
poCheckBox = new QCheckBox();
ThisTreeWidget->setItemWidget(poRecord, 1, poCheckBox);
poCheckBox->connect(poCheckBox, SIGNAL(stateChanged(int state)), this, SLOT(changechilditemCheckboxStatus(poRecord, state)));

I'm not very sure whether this is the rite way to do this, but it doesnt seem to work , so I must be doing something wrong. Would appreciate it if someone could point a direction for me to go on. Thanx

Harpo, newbie

Mad Max
28th February 2006, 10:35
I'm not very sure whether this is the rite way to do this, but it doesnt seem to work , so I must be doing something wrong. Would appreciate it if someone could point a direction for me to go on.
I just implemented a delegate class which do place to the last column some widget ( QToolButton in my case ) and move this column on the first pos. The using of delegates is very good described in Qt documentation. Also you could use
void QTreeWidgetItem::setCheckState ( int column, Qt::CheckState state )I think it would be better in your case.

harpo
1st March 2006, 13:58
I've solved the problem, thanks a lot for the input:)