In KDE every line edit has a clear button that appears when there is text.
How do I do that? Preferably something that doesn't require KDE.
Printable View
In KDE every line edit has a clear button that appears when there is text.
How do I do that? Preferably something that doesn't require KDE.
It's pure Qt the KDE people use. Just have a look into their sources and see how they make it. Or have a look at wysotas wwWidget. He also provide such a line edit.
In theory it is simply a button which overlays the line edit.
I found this, but the links to the source code are broken:
http://labs.trolltech.com/blogs/2007...-clear-button/
I figured out how to get a button into QLineEdit:
Code:
{ setLayout(layout); layout->addStretch(); layout->addWidget(clearButton); connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); clearButton->setFlat(true); clearButton->setIcon(QIcon("/usr/share/oxygen/icons/16x16/actions/edit-clear-locationbar-rtl.png")); }
Problem is that it's too wide, and for some reason the icon does not show in the button. Also, how do I give it a standard themeable icon, such as perhaps the "Cancel" or "Close Tab" icon?
This also gave me a cool idea: Integrate a "Go" button into the QLineEdit that would emit a returnPressed() signal! That way you don't have to manage two widgets and two signal/slot connections for many QLineEdit applications.