Ver Mensaje Individual
  #7 (permalink)  
Antiguo 01/12/2016, 03:55
dehm
 
Fecha de Ingreso: septiembre-2010
Mensajes: 494
Antigüedad: 13 años, 6 meses
Puntos: 10
Respuesta: Qt. Cómo evitar el modo de edición al avanzar con Tab

Bueno, pues no lo consigo.

He creado un delegado para las celdas.
En la función createEditor() he añadido el filtro de eventos:

Código C++:
Ver original
  1. QWidget* MiDelegado::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const
  2. {
  3.     const QAbstractItemModel* model = index.model();
  4.     if (!model)
  5.     {
  6.         return QStyledItemDelegate::createEditor(parent,option,index);
  7.     }
  8.     QLineEdit* miEditor = new QLineEdit(parent);
  9.     QRegExpValidator* validadorEdad = new QRegExpValidator(QRegExp("[0-9.,]{1,10}"),miEditor);
  10.     miEditor->setValidator(validadorEdad);
  11.     miEditor->setAlignment(Qt::AlignLeft);
  12.     miEditor->installEventFilter(filter);
  13.     return miEditor;
  14. }

Pero ahora, cuando estoy con el filtro de eventos, veo que responde a todas las pulsaciones de teclas menos a la del tabulador, y ahí me he quedado...

Código C++:
Ver original
  1. bool Filter::eventFilter(QObject *object, QEvent *event)
  2. {  
  3.     QLineEdit *editor = dynamic_cast<QLineEdit*>(object);
  4.     if (!editor)
  5.     {
  6.         return false;
  7.     }
  8.     if (event->type() == QEvent::KeyPress)
  9.     {
  10.         QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
  11.         qDebug()<<event->type();
  12.  
  13.         if (keyEvent->key() == Qt::Key_Tab)
  14.         {
  15.             qDebug()<<"Tab";
  16.             //QModelIndex current = editor->parent()->objectName();
  17.             //qDebug()<<editor->parent()->objectName();
  18.  
  19.             //qDebug()<<editor->parent()->objectName();
  20.  
  21.             return true;
  22.         }
  23.     }
  24.     return false;
  25. }

Es curioso porque es la única tecla que no considera
__________________
Mi calculadora en Qt