title: qlineedit auto resize to content
body: <p>I'm trying to do a small widget with a lineedit and a pushbutton.  If the button is clicked, it should open a filedialog where I can select a file. The file name should then showed in the lineedit. Here is what i got so far:</p>
  
  <pre><code>#include "widget_openimage.h"
  #include &lt;QFontMetrics&gt;
  
  Widget_openimage::Widget_openimage(QWidget *parent) : QWidget(parent) {
  
  // horizontal layout
  layout = new QHBoxLayout();
  
  // linedit on the left which shows the path of the chosen file
  lineedit = new QLineEdit();
  lineedit-&gt;setReadOnly(true);
  
  // pushbutton on the right to select the file
  btn = new QPushButton("...");
  btn-&gt;setFixedSize(20,20);
  connect(btn, SIGNAL(clicked()), this, SLOT(btn_clicked()));
  connect(lineedit, SIGNAL(textChanged(QString)), this, SLOT(resize_to_content()));
  
  layout-&gt;addWidget(lineedit);
  layout-&gt;addWidget(btn);
  this-&gt;setLayout(layout);
  }
  
  void Widget_openimage::btn_clicked() {
  QString filename = QFileDialog::getOpenFileName(this,tr("Open"), "", tr("Image Files (*.png *.jpg *.bmp));
  if (filename.isEmpty())
  return;
  else {
        lineedit-&gt;setText(filename);
       }
  }
  
  void Widget_openimage::resize_to_content() {
  QString text = lineedit-&gt;text();
  QFontMetrics fm = lineedit-&gt;fontMetrics();
  int width = fm.boundingRect(text).width();
  lineedit-&gt;resize(width, lineedit-&gt;height());
  }
  </code></pre>
  
  <p>the openfile function of the button works fine, and the right path is shown in the lineedit too. however the resize doesnt work. can anyone lend me a hand?</p>