PDA

View Full Version : How to properly use tab-key in a QTreeWidget focus chain for custom editors



danki
1st February 2012, 18:34
Hi everybody,

I am working on a QTreeWidget whose the first column shows a property label and the second column shows the corresponding property value.
I successfully used a QStyleItemDelegate to open a simple editor (say QLineEdit, QDateEdit, ...), set the actual data and get the modified data.
In this situation the tab-key works as expected: The next item is edited and receives the focus with the actual text selected.

The problem comes when I want to use a custom QWidget with for example a QPushButton and a QLineEdit. In the constructor of this
widget I used setFocusProxy on the QLineEdit and thus, clicking in an item edits it and the actual text is selected. Well. But when I use
the tab-key the QLineEdit loses the focus (Ok) but the next item in the QTreeWidget is not selected for edition.

I tried to play with focusNextPrevChild, eventFilter and so on, but nothing works.

Has somebody a solution or an example of how to fix this problem? Thanks a lot in advance.

PS1: I'm sorry for my poor English.
PS2: I used the following code for focusNextPrevChild:



bool CustomWidget::focusNextPrevChild( bool bNext )
{
setFocusProxy(0);
setFocus( Qt::TabFocusReason );
return QWidget::focusNextPrevChild(bNext);
}