Question about a simpler way to support in-cell text editing of only a single column within a Qt 4.4 QTreeWidget.

From:    Philip Weinstein, CADSWES
Edit:   9-17-2009 / minor: 9-18-2009
E-mail:   philw@cadswes.colorado.edu
Phone:   303-492-5705
URL:   http://cadswes2.colorado.edu/~philw/2009/QtQuestions/QTreeWidgetEditing/

We want only a single column within this table (QTreeWidget) to have editable cells.

An edit operation is started by double-clicking in a cell within the "User Column Label" column:

  CLICK HERE TO SEE C++ CODE EXCERPT  

Note: "Slot" is a basic data element in our application (RiverWare). It is not related to Qt "slots" (which are Qt "signal handlers").

In Qt 4.4, a QTreeWidgetItem is made editable by setting a bit within its Qt::ItemFlags property. The setting of this flag is implemented in this method:

If editing for the QTreeWidgetItem is enabled, an incell edit is started by double-clicking in any cell, as built-in behavior. There isn't a virtual method in QTreeWidget or QTreeWidgetItem which we can define to override this behavior. Also, there is no way to enable cell editing for just one particular column. There is, however, an itemDoubleClicked Qt Signal we can receive (via a Qt slot method).

In our current implementation, editing for all QTreeWidgetItems is generally disabled. We dynamically, conditionally enable editability of a single QTreeWidgetItem and start an edit operation when the user double-clicks on an item -- depending on the clicked column. See "slot" method:

If the user completes the edit (i.e. rather than aborting the edit, e.g. with the ESC key), we process the new text and disable editability of the item in the following "slot" method:

But because there doesn't seem to be a way to retrieve a pointer to the QLineEdit created for the in-cell edit session, we don't have a good way of knowing that the user has aborted the edit, e.g. by hitting the ESC key. This is important because we need to re-disable editability of the item. We do this by unconditionally disabling item editability of ALL items in each of these "slot" methods:

See the implementation for disabling item editability of ALL items in this method:

Is there a simpler way to provide in-cell editing within a QTreeViewItem, limited to particular columns?

--- (end) ---