Hi,
here now a part of my solution.
Delegate
{
if (index.row()%2 && (index.column()==1 || index.column()==2))
{
connect(dualValEditor,
SIGNAL(commitData
(QWidget*)),
this,
SIGNAL(commitData
(QWidget*)));
return dualValEditor;
}
return QStyledItemDelegate::createEditor(parent, option, index);
}
QWidget* TableDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
if (index.row()%2 && (index.column()==1 || index.column()==2))
{
EvaDualValEditor* dualValEditor = new EvaDualValEditor(new QDateTimeEdit(parent), new QDateTimeEdit(parent), parent);
connect(dualValEditor, SIGNAL(commitData(QWidget*)), this, SIGNAL(commitData(QWidget*)));
connect(dualValEditor, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)), this, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)));
return dualValEditor;
}
return QStyledItemDelegate::createEditor(parent, option, index);
}
To copy to clipboard, switch view to plain text mode
DualValEditor
, wgt1(editor1)
, wgt2(editor2)
{
if (editor1 && editor2)
{
init();
setFocusPolicy(Qt::StrongFocus);
setFocusProxy(wgt1);
setTabOrder(wgt1, wgt2);
wgt1->installEventFilter(this);
wgt2->installEventFilter(this);
}
}
EvaDualValEditor::EvaDualValEditor( QWidget* editor1, QWidget* editor2, QWidget *parent)
: QWidget(parent)
, wgt1(editor1)
, wgt2(editor2)
{
if (editor1 && editor2)
{
init();
setFocusPolicy(Qt::StrongFocus);
setFocusProxy(wgt1);
setTabOrder(wgt1, wgt2);
wgt1->installEventFilter(this);
wgt2->installEventFilter(this);
}
}
To copy to clipboard, switch view to plain text mode
bool EvaDualValEditor::focusNextPrevChild( bool next )
{
Qt::FocusReason reason = next ? Qt::TabFocusReason : Qt::BacktabFocusReason;
if (next)
{
if (wgt1->hasFocus())
{
wgt2->setFocus(reason);
return true;
}
else if(wgt2->hasFocus())
{
setFocusProxy(wgt2);
emit commitData(this);
setFocusProxy(tmp);
return true;
}
}
else if(!next)
{
if (wgt2->hasFocus())
{
wgt1->setFocus(reason);
return true;
}
else if(wgt1->hasFocus())
{
emit commitData(this);
return true;
}
}
return QWidget::focusNextPrevChild(next
);
}
bool EvaDualValEditor::focusNextPrevChild( bool next )
{
Qt::FocusReason reason = next ? Qt::TabFocusReason : Qt::BacktabFocusReason;
if (next)
{
if (wgt1->hasFocus())
{
wgt2->setFocus(reason);
return true;
}
else if(wgt2->hasFocus())
{
QWidget* tmp = focusProxy();
setFocusProxy(wgt2);
emit commitData(this);
emit closeEditor(this, QAbstractItemDelegate::EditNextItem);
setFocusProxy(tmp);
return true;
}
}
else if(!next)
{
if (wgt2->hasFocus())
{
wgt1->setFocus(reason);
return true;
}
else if(wgt1->hasFocus())
{
emit commitData(this);
emit closeEditor(this, QAbstractItemDelegate::EditPreviousItem);
return true;
}
}
return QWidget::focusNextPrevChild(next);
}
To copy to clipboard, switch view to plain text mode
This works exactly as desired.
Bookmarks