Integrate a search icon in QlineEdit
-
Hello, every one
i want to add a search image in the right side of QlineEdit
when i cilck this icon a function will be called
@
QLineEdit lineEdit;
lineEdit.addimage("In the right side);
image.isclicked()
{do some thing }
@
-
Is this "QwwClearLineEdit":http://www.wysota.eu.org/wwwidgets/doc/html/qwwclearlineedit.html what you are looking for ? Follow "wwwidgets":http://www.wysota.eu.org/wwwidgets/
-
thanks p3c0, but i'm looking to add a search icon inside my qlineEdit
in the right side of it
i hope your understand me
-
here you go:
@
MyLineEdit::MyLineEdit(QWidget* parent)
: QLineEdit(parent)
{
m_SearchButton = new QPushButton(this);
m_SearchButton->setIcon(...);
m_SearchButton->setIconSize(16,16);
connect(m_SearchButton, SIGNAL(clicked()), this, SIGNAL(returnPressed()));
}void MyLineEdit::resizeEvent(QResizeEvent* event)
{
QLineEdit::resizeEvent(event);
this->layoutSearchbutton();
}void MyLineEdit::layoutSearchButton()
{
this->ensurePolished();
QSize size = m_Searchbutton->minimumSizeHint();
int x = this->rect().right() - size.widht();
int y = ( this->rect().height() - size.height() ) / 2.0;
m_SearchButton->setGeometry( QPoint(x,y), size );//maybe the size has changed so we better set the text margins again
int left, top, bottom;
this->getTextMargins ( &left, &top, 0, &bottom );
this->setTextMargins( left, top, 2 + size.width() + 2, bottom );
}
@
i wrote it out of my mind so i haven't tested it though if it compiles. But it should do what you expect.If you just want to display the icon instead of the button replace it with a QLabel.
Also you can apply a stlylesheet to the button/label to remove the border and set the background to transparent, etc. -
Ok. May be the sources would help you.
-
thank you , i have take a look at the source , but it is hard to me to understand it
-
Try this "LineEditWithClearButton":http://git.forwardbias.in/?p=lineeditclearbutton.git;a=blob;f=lineedit.cpp;hb=HEAD
-
for a custom widget the examples so far should work
if you need something similar without subclassing "this":http://www.qtcentre.org/threads/6158-Search-box might work too, especially by using an horizontal layout and appropriate vertical/horizontal policies for the button ( I would use a flat QPushButton instead)