0
votes

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 *)
{

}
1

1 Answers

1
votes

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
}