PDA

View Full Version : Multiple clicks required to get into edit mode on QTreeView



JonInAnnArbor
7th August 2008, 14:59
Hello:

I have a QTreeView (rootIsDecorated=false) with a QItemDelegate on the first column that uses a QLineEdit for editing. I have set editTriggers to QAbstractItemView::AllEditTriggers.

PROBLEM: In order to get into edit mode on that column I sometimes need to click up to 3 times.


Is there any technique to ensure that I get edit mode the very first time I click in the cell? :confused:

The flags returned by my model are:

if (0 == index.column())
{
return flags | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
}

It may even be ideal if that column was always in edit mode?

I set up a custom widget that uses vector if QLineEdits in a QVBoxLayout positioned next to a QTreeView for this effect, but then I must synchronize the vector of QLineEdits and the Model-View. Not exactly ideal...

Any help would be greatly appreciated.

best regards,
Jon K.
Ann Arbor Michigan U.S.A.

spirit
7th August 2008, 15:24
try to catch signal


void QAbstractItemView::clicked ( const QModelIndex & index )


and then in slot to do


void QAbstractItemView::openPersistentEditor ( const QModelIndex & index )

JonInAnnArbor
7th August 2008, 17:20
Hello:

Thanx for the advise.

Unfortunately this does not seem to do the trick. I tried this and variations on it, including the mouse events, to no avail. :(

Any other thoughts?


best regards,
Jon K
Ann Arbor Michigan

JonInAnnArbor
7th August 2008, 17:21
Oh, by the way...

I am using Qt 4.4 on Mac OS X and MS-Windows.


best regards,
Jon K
Ann Arbor Michigan U.S.A.

spirit
7th August 2008, 17:28
do you inherit QTreeView or just use it like a widget?

JonInAnnArbor
7th August 2008, 17:48
Hello:

I have a view class derived from QTreeView, primarily to make it be a fixed number of rows. In my derived class is where I hooked up the signal/slot connections, and tried to catch the mouse events.

best regards,
Jon K

stefan
7th August 2008, 19:21
maybe this will help you. In .NET :rolleyes: ther is control property called EditMode, and when you put it on EditOnEnter your problem is solved. EditTriggers should be simmilar..

editTriggers : EditTriggers
This property holds which actions will initiate item editing.
This property is a selection of flags defined by EditTrigger, combined using the OR operator. The view will only initiate the editing of an item if the action performed is set in this property.
Access functions:

EditTriggers editTriggers () const
void setEditTriggers ( EditTriggers triggers )

enum QAbstractItemView::EditTrigger
flags QAbstractItemView::EditTriggers
This enum describes actions which will initiate item editing.

QAbstractItemView:: NoEditTriggers, 0, No editing possible.
QAbstractItemView:: CurrentChanged, 1, Editing start whenever current item changes.
QAbstractItemView:: DoubleClicked, 2, Editing starts when an item is double clicked.
QAbstractItemView:: SelectedClicked, 4, Editing starts when clicking on an already selected item.
QAbstractItemView:: EditKeyPressed, 8, Editing starts when the platform edit key has been pressed over an item.
QAbstractItemView:: AnyKeyPressed, 16, Editing starts when any key is pressed over an item.
QAbstractItemView:: AllEditTriggers, 31, Editing starts for all above actions.

JonInAnnArbor
7th August 2008, 20:39
Hello:

Yes, edit triggers is precisely the means I supposed would address this interaction. I have set the edit triggers value to AllEditTriggers.

Should this not have done the trick?

Thanx for your thoughts.


Jon K
Ann Arbor Michigan U.S.A.

jpn
7th August 2008, 20:53
Have you reimplemented any event handlers? Perhaps you forgot to call base class implementation..

JonInAnnArbor
7th August 2008, 21:26
Have you reimplemented any event handlers? Perhaps you forgot to call base class implementation..

Hello:

My derived class only re-implements sizeHint so I can make it a fixed height for a fixed number of rows.

Is that valid?

I briefly changed my code to use a QTreeView directly and it did not seem to have much of an impact...


best regards,
Jon K
Ann Arbor Michigan U.S.A.

ykozlov
26th November 2012, 19:59
I had the same problem and was able to fix it by leaving the default edit triggers and connecting the view's clicked(QModelIndex) signal to its edit(QModelIndex) slot.