This is my scenario:
A MainWindow
with a single central widget that is a QTabWidget
, plus its QToolBar
. Each time I open a new document, an instance of a class that contains two QTabWidget
and% QTableView
is inserted within QTextEdit
.
The QTableView
have a filter of events that cause them to react in a special way to certain function keys, and that works perfectly. However, when I press keys like Ctrl+C
, Ctrl+V
or Ctrl+X
I get an error type:
QAction :: eventFilter: Ambiguous shortcut overload: Ctrl + V *
Within the QToolBar
I have defined those actions (Copy, Paste and Cut), with their buttons and keyboard shortcuts.
For the error of Ambiguous shortcut overload
set shortcutContext
to WidgetWithChildrenShorCut
, in each of these actions.
The problem is that I am not able to capture the key combination Ctrl+Tecla
, or at least nothing happens when I do it.
This is an excerpt from the event filter:
bool Filter::eventFilter(QObject *obj, QEvent* event)
{
qDebug()<<obj->objectName();
TablaBase* table = qobject_cast<TablaBase*>(obj);
if( !table )
{
return QObject::eventFilter(obj, event);;
}
if (event->type() == QEvent::KeyPress)
{
QModelIndex indice = table->currentIndex();
QKeyEvent *ke =static_cast<QKeyEvent*>(event);
if (ke->matches(QKeySequence::Copy))//primer intento de capturar!!!
{
qDebug()<<"Copiando 1";
return true;
}
switch (ke->key())
{
//segundo intento!!!!
case(Qt::Key_C):// && (ke->modifiers().testFlag(Qt::ControlModifier))):
{
if (ke->modifiers()==Qt::ControlModifier)
{
qDebug()<<"Copiando 2";
return true;
break;
}
}
default:
{
return false;
break;
}
}
}
return QObject::eventFilter(obj, event);
}