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

Qt-interest Archive, April 2007
QTableWidget question


Message 1 in thread

Hi There,

I have a QMainWindow based application in which there are a few objects, one
is a QTreeWidget*. The issue is that the user edits the items in the widget,
types some text and then without pushing enter or focusing out, he/she
clicks on the menu and selects File/Save. Then my code goes through the
table like:
	QString Entry1, Entry2, Entry3;
	for (int i = 0; i < pTable->rowCount(); i++) {
		Entry1 = pTable->item(i, 0)->text();
		Entry2 = pTable->item(i, 1)->text();
		Entry3 = pTable->item(i, 2)->text();
	}
All fine, except for that the QTreeWidgetItem which is being edited, has the
focus (although it looks hat the item cannot have the focus just the
QTreeWidget) and its value is not committed yet is not in the list and empty
string is returned by ->text().

How is that possible to put an end to the editing or get the text which is
still being edited? The QTreeWidgetItem should not lose focus (or it shall
be restored).

Thanks,
Sandor

--
 [ signature omitted ] 

Message 2 in thread

The QTableView  (from which QTableWidget is derived) ends editing when the 
table/cell lose focus.  Perhaps you could create your own custom view/model/delegate.

Then you could tailor how/when the editing ends & begins.

The QTableWidget is a convenience widget that implements a default view/model/delegate.

HTH,
Susan


----- Original Message ----
From: Hadas Sandor <Sandor.Hadas@xxxxxxxx>
To: "qt-interest@xxxxxxxxxxxxx" <qt-interest@xxxxxxxxxxxxx>
Sent: Thursday, April 5, 2007 9:16:14 AM
Subject: QTableWidget question

Hi There,

I have a QMainWindow based application in which there are a few objects, one
is a QTreeWidget*. The issue is that the user edits the items in the widget,
types some text and then without pushing enter or focusing out, he/she
clicks on the menu and selects File/Save. Then my code goes through the
table like:
    QString Entry1, Entry2, Entry3;
    for (int i = 0; i < pTable->rowCount(); i++) {
        Entry1 = pTable->item(i, 0)->text();
        Entry2 = pTable->item(i, 1)->text();
        Entry3 = pTable->item(i, 2)->text();
    }
All fine, except for that the QTreeWidgetItem which is being edited, has the
focus (although it looks hat the item cannot have the focus just the
QTreeWidget) and its value is not committed yet is not in the list and empty
string is returned by ->text().

How is that possible to put an end to the editing or get the text which is
still being edited? The QTreeWidgetItem should not lose focus (or it shall
be restored).

Thanks,
Sandor

--
 [ signature omitted ] 

Message 3 in thread

Thanks for the advice, subclassing was needed indeed (which I do not really
like since this feature semt to be a basic one to me).

Just for the record as someone else might run into the same problem, the
solution is to subclass QTableWidget and from there call
commitData(cellWidget(currentRow(), currentColumn()));

Cheers,
Sandor

-----Original Message-----
From: Susan Macchia [mailto:susan@xxxxxxxxxxxx]
Sent: 05/04/2007 18:38
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: QTableWidget question


The QTableView  (from which QTableWidget is derived) ends editing when the 
table/cell lose focus.  Perhaps you could create your own custom
view/model/delegate.

Then you could tailor how/when the editing ends & begins.

The QTableWidget is a convenience widget that implements a default
view/model/delegate.

HTH,
Susan


----- Original Message ----
From: Hadas Sandor <Sandor.Hadas@xxxxxxxx>
To: "qt-interest@xxxxxxxxxxxxx" <qt-interest@xxxxxxxxxxxxx>
Sent: Thursday, April 5, 2007 9:16:14 AM
Subject: QTableWidget question

Hi There,

I have a QMainWindow based application in which there are a few objects, one
is a QTreeWidget*. The issue is that the user edits the items in the widget,
types some text and then without pushing enter or focusing out, he/she
clicks on the menu and selects File/Save. Then my code goes through the
table like:
    QString Entry1, Entry2, Entry3;
    for (int i = 0; i < pTable->rowCount(); i++) {
        Entry1 = pTable->item(i, 0)->text();
        Entry2 = pTable->item(i, 1)->text();
        Entry3 = pTable->item(i, 2)->text();
    }
All fine, except for that the QTreeWidgetItem which is being edited, has the
focus (although it looks hat the item cannot have the focus just the
QTreeWidget) and its value is not committed yet is not in the list and empty
string is returned by ->text().

How is that possible to put an end to the editing or get the text which is
still being edited? The QTreeWidgetItem should not lose focus (or it shall
be restored).

Thanks,
Sandor

--
 [ signature omitted ]