Maybe I wasn't clear: the second item has the longest string and I would expect the QTreeWidget to grow to show the whole string.
I added an example with the content of the QTreeWidget.
Any ideas why it doesn't resize to the longest string?


Qt Code:
  1. #include <QVBoxLayout>
  2. #include <QLineEdit>
  3. #include <QTreeWidget>
  4. #include <QLineEdit>
  5. #include <QTreeWidget>
  6.  
  7. MyWidget::MyWidget(QWidget *parent)
  8. : QWidget(parent)
  9. {
  10. setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
  11.  
  12. QVBoxLayout *vBoxLayout = new QVBoxLayout(this);
  13. vBoxLayout->setContentsMargins(1, 1, 0, 0);
  14. QLineEdit *mLineEdit = new QLineEdit;
  15.  
  16. vBoxLayout->addWidget(mLineEdit);
  17.  
  18. QTreeWidget *treeWidget = new QTreeWidget;
  19. item->setText(0, "The quick brown fox jumps over the lazy dog");
  20. treeWidget->addTopLevelItem(item);
  21. item2->setText(0, "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog");
  22. treeWidget->addTopLevelItem(item2);
  23. item3->setText(0, "The quick brown");
  24. treeWidget->addTopLevelItem(item3);
  25.  
  26.  
  27. treeWidget->setWindowFlags(Qt::Popup);
  28. treeWidget->setFocusPolicy(Qt::NoFocus);
  29. treeWidget->setMouseTracking(true);
  30. treeWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  31.  
  32. treeWidget->setColumnCount(1);
  33. treeWidget->setUniformRowHeights(true);
  34. treeWidget->setRootIsDecorated(false);
  35. treeWidget->setEditTriggers(QTreeWidget::NoEditTriggers);
  36. treeWidget->setSelectionBehavior(QTreeWidget::SelectRows);
  37. treeWidget->setFrameStyle(QFrame::Box | QFrame::Plain);
  38. treeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  39. treeWidget->header()->hide();
  40. treeWidget->resizeColumnToContents(0);
  41.  
  42. mLineEdit->installEventFilter(this);
  43. vBoxLayout->addWidget(treeWidget);
  44. connect(mLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(updateList(const QString&)));
  45. connect(treeWidget, SIGNAL(itemClicked( QTreeWidgetItem*, int)), SLOT(updateLineEdit(QTreeWidgetItem*, int)));
  46. move(QCursor::pos());
  47. show();
  48. mLineEdit->setFocus();
  49. setLayout(vBoxLayout);
  50. layout()->setSizeConstraint(QLayout::SetFixedSize);
  51. }
To copy to clipboard, switch view to plain text mode