Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] ignore key press into editText?

[solved] ignore key press into editText?

Scheduled Pinned Locked Moved General and Desktop
qtextedeventeventfilter
2 Posts 1 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Giorgi
    wrote on 29 May 2015, 07:35 last edited by Giorgi
    #1

    how can I ignore key in key event in QTextEdit? if user pushs Enter key I want handle enter press event but I want to ignore new line into editText. how to do this?

    bool MyTextEdit::eventFilter(QObject *target, QEvent *event)
    {
        if(event->type() == QKeyEvent::KeyPress){
    
            QKeyEvent *key = static_cast<QKeyEvent*>(event);
            if(key->key() == Qt::Key_Enter){
                qDebug() << "ok I can handle event here ";
                event->ignore();
                return true;
            }
    
        }
            
        return QObject::eventFilter(target, event);
    }
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      Giorgi
      wrote on 29 May 2015, 08:49 last edited by Giorgi
      #2

      I found solution. i remplemented keyPressEvent from QTextEdit class

      void MyTextEdit::keyPressEvent(QKeyEvent *e)
      {
          if(e->key() == 16777220){
             //enter clicked
              return;
          }
      
          return QTextEdit::keyPressEvent(e);
      }
      
      
      1 Reply Last reply
      0

      1/2

      29 May 2015, 07:35

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved