I figured out how to get a button into QLineEdit:

Qt Code:
  1. EnhancedLineEdit::EnhancedLineEdit(QWidget *parent) :
  2. QLineEdit(parent)
  3. {
  4. QHBoxLayout *layout = new QHBoxLayout(this);
  5. setLayout(layout);
  6. layout->addStretch();
  7.  
  8. QPushButton *clearButton = new QPushButton(this);
  9. layout->addWidget(clearButton);
  10. connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
  11.  
  12. clearButton->setFlat(true);
  13. clearButton->setCursor(QCursor(Qt::ArrowCursor));
  14. clearButton->setIcon(QIcon("/usr/share/oxygen/icons/16x16/actions/edit-clear-locationbar-rtl.png"));
  15. }
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.