nilkkiz
nilkkiz

Reputation: 41

keyPressEvent denies writing to QLineEdit

I faced an error and I didn't found any solutions for this problem. So I have made a subclass from QLineEdit, and overrided a keyPressEvent method. Now if I try to write something it doesn't allow it, but it triggers the event. Any advices?

.h

class PlayerQLineEdit : public QLineEdit
{
public:
    PlayerQLineEdit();

    void keyPressEvent(QKeyEvent *);
};

.cpp

PlayerQLineEdit::PlayerQLineEdit()
{
    setDisabled(false);
}

void PlayerQLineEdit::keyPressEvent(QKeyEvent *)
{

}

Upvotes: 0

Views: 136

Answers (1)

Maxim Paperno
Maxim Paperno

Reputation: 4859

You have to call the base class event handler. Otherwise the line edit can't get any key presses!

void PlayerQLineEdit::keyPressEvent(QKeyEvent *event)
{
  // ... do stuff 
  // optionally return before calling base class handler to suppress key strokes.
  QLineEdit::keyPressEvent(event);
  // ... do stuff
}

Upvotes: 2

Related Questions