0
这是我的问题。当我在QTableView中编辑单元格时,如果按TAB键,当前单元格会更新,但下一个单元格不处于编辑模式。如何在编辑QTableView中的单元格之后使用Tab键前进时避免编辑模式?
我尝试在表中创建一个eventFilter,但它不起作用。如果我在委托的编辑器小部件中创建eventFilter, 这是我在QTableView中尝试的一个eventFilter。我的想法是,如果当前单元格在最后一列和当前行并且当前行不是空的,我插入另一行(这工作正常),如果我正在编辑任何单元格,当按TAB时,我可以放置在下一行细胞,但没有编辑模式
这是代码片段:
bool MiTabla::eventFilter(QObject *watched, QEvent *e)
{
if (e->type() == QEvent::KeyPress)
{
QModelIndex indice = this->currentIndex();
QKeyEvent *ke =static_cast<QKeyEvent*>(e);
switch (ke->key())
{
case (Qt::Key_Delete):
{
if (this->selectionModel()->isRowSelected(indice.row(),QModelIndex()))
{
//borrarLineas();
}
else
{
this->model()->setData(this->currentIndex(),"",Qt::EditRole);
}
break;
}
case (Qt::Key_Tab):
{
if (indice.row() == this->model()->rowCount(QModelIndex())-1
&& indice.column() == this->model()->columnCount(QModelIndex())-1
&& !NombreVacio())
{
this->model()->insertRow(this->model()->rowCount(QModelIndex()));
QModelIndex ind = this->model()->index(indice.row()+1,0);
this->setCurrentIndex(ind);
}
else //this doesn't work
{
QModelIndex ind = this->model()->index(indice.row(),indice.column()+1);
this->setCurrentIndex(ind);
}
break;
解决方案草图:子类QStyledItemDelegate,重写它的'eventFilter',为Tab键做一个稍微不同的处理,否则调用基类实现。参看内置处理:https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qabstractitemdelegate.cpp.html#476 – peppe
eventFilter方法的返回值是什么?你是否试图为'Key_Tab'情况返回“true”? – ramzes2
谢谢佩佩。这只是我正在寻找。和ramzes2,另一个线索是返回false让表“按下”使用TabKey – user3733164