I can't find
-
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.
-
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.
-
@mrjj for an example, I have many lineEdit object: lineEditname, lineEditage, lineEditaddress, lineEditPhoneNumber and I want when click one of them, it will change styleSheet of its. How can I do it?
-
@Duy-Khang
So if you want to do that make all your line edits be @mrjj'sMyLineEdit
, then the code he shows there will apply to all of them