How to do - QToolButton inside the QlineEdit : Qt5

qlineedit, qpushbutton, qt5, windows

Solution

//Create QToolButton:

QToolButton *clearButton = new QToolButton(this);
QPixmap pixmap(":/new/AppResource/images/clear_button.png");
clearButton->setIcon(QIcon(pixmap));
clearButton->setIconSize(pixmap.size());
clearButton->setCursor(Qt::ArrowCursor);
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
clearButton->hide();

Connect Signal-Slot:

connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));

Visible on Text Enter into serach box:

clearButton->setVisible(true);

Problem

I want to add `QToolButton` inside the `QLineEdit`. I want to clear the text of `QLineEdit` control on that button click. For example how in google image: I have looked : This `StackOverflow article` But still not solved my issue. Thanks in Advance.

Original source

Related problems