I figured out how to get a button into QLineEdit:
EnhancedLineEdit
::EnhancedLineEdit(QWidget *parent
) :{
setLayout(layout);
layout->addStretch();
layout->addWidget(clearButton);
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
clearButton->setFlat(true);
clearButton
->setCursor
(QCursor(Qt
::ArrowCursor));
clearButton
->setIcon
(QIcon("/usr/share/oxygen/icons/16x16/actions/edit-clear-locationbar-rtl.png"));
}
EnhancedLineEdit::EnhancedLineEdit(QWidget *parent) :
QLineEdit(parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
setLayout(layout);
layout->addStretch();
QPushButton *clearButton = new QPushButton(this);
layout->addWidget(clearButton);
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
clearButton->setFlat(true);
clearButton->setCursor(QCursor(Qt::ArrowCursor));
clearButton->setIcon(QIcon("/usr/share/oxygen/icons/16x16/actions/edit-clear-locationbar-rtl.png"));
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks