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. Selective keyPressEvent, filter for dedicated sender QLineEdit

Selective keyPressEvent, filter for dedicated sender QLineEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
qkeyeventqlineeditqkeypressevent
2 Posts 2 Posters 1.6k 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.
  • R Offline
    R Offline
    Ralf
    wrote on last edited by Ralf
    #1

    I've created a QWidget, which contains three QLineEdits. Then I added a overwrote the keyPressEvent so that this lineEdit_3 reacts on key press. Working good.

    void MySuperWidget::keyPressEvent(QKeyEvent* keyEv) {
    switch (keyEv->key()) {
    case Qt::Key_Up:
    //.. stuff
    break;

    case Qt::Key_Down: {
        //.. stuff
        }
        break;
      default:
        break;
    }
    

    }

    BUT the first and second QLineEdit also react on keypress :(

    I need somethng like this:

    if (sender() != ui->lineEdit_3 ) {
    keyEv->ignore();
    }

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      You need to accept the event so the parent knows that the event has been handled. Otherwise the event will go all children until someone accepts it or if none do, it will be ignored.
      so keyEv->accept() should do the trick.

      Greetz, Jeroen

      1 Reply Last reply
      0

      • Login

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