Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, February 2007
controlling QTreeView cells


Message 1 in thread

Hi,

I have a QTreeView that looks something like this at runtime:
---------------------------------------------
|Process            | Initials | Date       |
---------------------------------------------
|Visual Inspection  | TDB      | 02/02/2007 |
---------------------------------------------
|Chassis Assembly   |          |            |
---------------------------------------------

What I would like to accomplish is this:
1) Automatically fill in the initials of the user when the cell under the 
'Initials' column is double clicked. 
2) Auto set the corresonding date column at the same time.

I was playing around with a custom subclass of QItemDelegate using a 
QPushButton as the editor. I can get it to work for 1) if I double click and 
then hit 'Enter'. I also tried playing around with the event filter for the 
QTreeView, but that didn't work. Any ideas on how to get 1) to work? Then how 
would I go about 2)?

Thanks,
Tom

PS: I am using Qt 4.2.2.

--
 [ signature omitted ] 

Message 2 in thread

Tom Brown wrote:

>Hi,
>
>I have a QTreeView that looks something like this at runtime:
>---------------------------------------------
>|Process            | Initials | Date       |
>---------------------------------------------
>|Visual Inspection  | TDB      | 02/02/2007 |
>---------------------------------------------
>|Chassis Assembly   |          |            |
>---------------------------------------------
>
>What I would like to accomplish is this:
>1) Automatically fill in the initials of the user when the cell under the 
>'Initials' column is double clicked. 
>2) Auto set the corresonding date column at the same time.
>
>  
>
1) set each item editable (double click/press F2 allows keyborad in)
item->setFlags(item->flags() | Qt::ItemIsEditable);
2) Connect itemChanged signal to a slot
disconnect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)),
this, SLOT(updateDomElement(QTreeWidgetItem *, int)));

3) make the change on both tree view and dom data.
void xxx::updateDomElement(QTreeWidgetItem *item, int column)
{
if (column == 1)
{
QDomElement oldElement = … ;
QDomElement newElement = … ;
QDomText newText = domDocument.createTextNode(…);
newElement.appendChild(newText);
element.replaceChild(newElement, oldElement);

// update the next column also
}
}

Lingfa

--
 [ signature omitted ] 

Message 3 in thread

On Friday 02 February 2007 14:03, Tom Brown wrote:
> Hi,
>
> I have a QTreeView that looks something like this at runtime:
> ---------------------------------------------
> |Process            | Initials | Date       |
> ---------------------------------------------
> |Visual Inspection  | TDB      | 02/02/2007 |
> ---------------------------------------------
> |Chassis Assembly   |          |            |
> ---------------------------------------------
>
> What I would like to accomplish is this:
> 1) Automatically fill in the initials of the user when the cell under the
> 'Initials' column is double clicked.
> 2) Auto set the corresonding date column at the same time.

I finally figured out how to do this and it was a lot easier than I thought. 
The key was to connect the doubleClicked() signal of the QTreeView to a 
custom slot and set the data there. Then using QModelIndex::sibling() I was 
able to set the date in the next column.

Thanks,
Tom

--
 [ signature omitted ]