Connecting the clear button of a QLineEdit to a custom slot
Solved
General and Desktop
-
Hi :-)
Is it possible to connect a
QLineEdit
's clear button that can be displayed viaQLineEdit::setClearButtonEnabled()
to a custom slot? I found https://bugreports.qt.io/browse/QTBUG-36257 which contains the following code to do so:for (int i(0); i < myLineEdit->children().size(); ++i) { QAction *myClearAction(qobject_cast<QAction *>(myLineEdit->children().at(i))); if (myClearAction) { connect(myClearAction, &QAction::triggered, myLineEdit, &QLineEdit::returnPressed, Qt::QueuedConnection); } }
but I wondered if anything has been changed concerning this since then. The solution posted will probably work, but looks a bit like a hack to me ;-)
-
Hi,
The alternative is for you to add your own action to the QLineEdit so you ensure that you have full control over it.