https://github.com/epasveer/qclearlineedit
QLineEdit that better handles the 'clear' action.
https://github.com/epasveer/qclearlineedit
qlineedit qt qt-framework qt-widgets
Last synced: 3 months ago
JSON representation
QLineEdit that better handles the 'clear' action.
- Host: GitHub
- URL: https://github.com/epasveer/qclearlineedit
- Owner: epasveer
- License: mit
- Created: 2022-06-06T23:03:37.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-06T23:26:04.000Z (almost 3 years ago)
- Last Synced: 2025-03-09T12:55:29.743Z (3 months ago)
- Topics: qlineedit, qt, qt-framework, qt-widgets
- Language: C++
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QClearLineEdit
A version of QLineEdit that better handles the 'clear' action.
The Qt QLineEdit can have a 'clear' button in the text field. This is enabled
with this function :
```
QLineEdit::setClearButtonEnabled(bool enable)
```Clicking on this button clears the text field. *However*, it doesn't emit any signal.
You must programatically check the text field. :^(QClearLineEdit is an extension of QLineEdit. It adds a way for the 'clear'
button to emit the 'returnPressed' signal.```
// Create the LineEdit
QClearLineEdit* lineEdit = new QClearLineEdit(parent);// Enable the new signal
lineEdit->enableReturnPressedOnClear();// Connect the signal to our method
QObject::connect(lineEdit, &QLineEdit::returnPressed, this, MyClass::handleReturnPressed);
```## To use:
Copy QClearLineEdit.h and QClearLineEdit.cpp to your project. Where ever you use QLineEdit, you can use
QClearLineEdit. Enable the new signal by calling:
```
lineEdit->enableReturnPressedOnClear();
```
QClearLineEdit can be used in 'Designer' by promoting 'QClearLineEdit' from 'QLineEdit'.