Item delegate editor focus problem
-
What do you mean by "Qt default delegates"? QItemDelegate and QStyledItemDelegate? Please note that I am deriving my delegate from QItemDelegate and thus already have implementations for editorEvent() and eventFilter().
-
It does not matter if you derive. And is does not matter which of them, the event handling is equal.
Read the code of those delegate. Look what they do when. Look how they handle tab, cursor, focus etc. This is all done by the delegates. And the default behavior might lead to your problems, as you have a different behaving widget.
Read the code of QItemDelegate and QTableView to understand what they do when and how they do it. Then perhaps you find a way, how you have to change things so your editor works!
I have a delegate (CombBox as auto filter) which in some cases opens a modal dialog. you then have to change that behavior. But to see what and where, you first have to read the Qt code.
So again: read the code of the trolls for that.
-
Yes, reading and understanding the code of the trolls will of course help me solve the problem. But it is a rather large chunk of code - QAbstractItemView is 4000 lines alone. Maybe I just hasn't got what it takes :-)
Thanks anyway.
-
At the end of your constructor add
@
setFocusProxy(l1);
@Also, create a new item delegate and reimplement
- createEditor
- setEditorData
- setModelData
@
QWidget *MyDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
return new MyEditorWidget(parent);
}void MyDelegate::setEditorData ( QWidget * editor, const QModelIndex & index ) const
{
if(MyEditorWidget *me = qobject_cast<MyEditorWidget *>(editor))
me->l1->setText(index.data(Qt::EditRole));
}void MyDelegate::setModelData ( QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const
{
if(MyEditorWidget *me = qobject_cast<MyEditorWidget *>(editor))
model->setData(index, me->l2->text());
}
@This should be all you need.
-
It doesn't work for me. The solution you suggest has several issues:
-
It is not possible to use tab to navigate between l1 and l2. If l1 has focus and tab is pressed MyEditorWidget will be closed and the next cell will be selected in the list view.
-
Minor issue: If an editor is opened on a cell and tab is pressed the focus moves to the next cell but an editor is not opened in the new cell (as it happens when the editor is a Qt widget - eg QSpinBox).
-
Bizarre issue: If an editor is opened on cell 1 with focus on l2 and tab is pressed the editor is closed and focus moves to cell 2. But if tab is pressed a second time nothing happens. If tab is pressed a third time focus moves to cell 4, skipping cell 3.
-
-
Set l2 to NoFocus.
Everything else regarding tab key cannot work, as the view intercepts the tab keys. You will have to change the view too, to make it work.
Regarding the second issue, that might go away with l2 on NoFocus too. I'd suggest you play around with setFocus on l1 and l2 a bit. It might be enough to have it on the outer container (MyEditWidget).
-
[quote author="Volker" date="1298461923"]Set l2 to NoFocus.
Everything else regarding tab key cannot work, as the view intercepts the tab keys. You will have to change the view too, to make it work.
Regarding the second issue, that might go away with l2 on NoFocus too. I'd suggest you play around with setFocus on l1 and l2 a bit. It might be enough to have it on the outer container (MyEditWidget).[/quote]
It' s the delegate implementation, as I already stated above.
- virtual bool Q(Styled)Itemdelegate::editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index )
- virtual bool Q(Styled)Itemdelegate::eventFilter ( QObject * editor, QEvent * event )
And this is the point, where you can change the logic for tab etc.
-
Seems I have the same problem. I tried to solve it like I described on SO: http://stackoverflow.com/questions/12145522/why-pressing-of-tab-key-emits-only-qeventshortcutoverride-event