I can't find
Unsolved
General and Desktop
-
Hi
You have to create a custom class that inherits QLineedit and
then you override
https://doc.qt.io/qt-5/qwidget.html#mousePressEventDepending on what you want its might also be possible to some degree with stylesheet but
that more for hover events. (holding mouse over the lineedit)class MyLineEdit : public QLineEdit { Q_OBJECT public: explicit MyLineEdit(QWidget *parent = nullptr) : QLineEdit(parent) {} protected: void mousePressEvent(QMouseEvent *event) override { QLineEdit::mousePressEvent(event); // call the base to allow normal operation too setStyleSheet(xxx); } };
You could also use an eventfiler to catch events.
https://doc.qt.io/qt-5/eventsandfilters.htmlThen you dont need the subclass but its get a bit messy if you have many LineEdits etc and its not as self-contained as the subclass.