Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.8
-
None
-
Fedora 41, KDE Plasma, Wayland
Description
Consider the following code
#include <QApplication> #include <QLineEdit> #include <QDialog> #include <QVBoxLayout> #include <QCompleter> #include <QStandardItemModel> #include <QIdentityProxyModel> class AdaptiveFilterProxy : public QIdentityProxyModel { Q_OBJECT public: using QIdentityProxyModel::QIdentityProxyModel; static constexpr int SearchRole = 2000; void setText(const QString &text) { if (text == m_text) return; m_text = text; // This signal must be emitted to invalidate the completer, and force it to filter its rows again. emit dataChanged(index(0, 0), index(rowCount() - 1, 0), {SearchRole}); } QVariant data(const QModelIndex &index, int role) const override { if (role != SearchRole) return QIdentityProxyModel::data(index, role); if (!m_text.isEmpty() && data(index, Qt::DisplayRole).toString().contains(m_text, Qt::CaseInsensitive)) { return m_text; } else { return ""; } return QVariant(); } private: QString m_text; }; int main(int argc, char**argv) { QApplication app(argc, argv); auto window = new QDialog; auto layout = new QVBoxLayout(window); auto lineEdit = new QLineEdit; layout->addWidget(lineEdit); auto model = new QStandardItemModel(window); model->appendRow(new QStandardItem("Hello")); model->appendRow(new QStandardItem("Hello 2")); model->appendRow(new QStandardItem("Hello 3")); auto completer = new QCompleter(window); lineEdit->setCompleter(completer); auto searchFilter = new AdaptiveFilterProxy(window); searchFilter->setSourceModel(model); QObject::connect(lineEdit, &QLineEdit::textChanged, searchFilter, &AdaptiveFilterProxy::setText); completer->setModel(searchFilter); completer->setFilterMode(Qt::MatchStartsWith); completer->setCompletionMode(QCompleter::PopupCompletion); completer->setCompletionRole(AdaptiveFilterProxy::SearchRole); window->show(); return app.exec(); } #include "main.moc"
When typing "H" into the lineedit the completion popup appears as expected. When then pressing "e" the popup turns into a top-level window with decoration and is no longer attached to the lineedit
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-130474 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
599349,1 | QCompleter: Set transient parent on popup | dev | qt/qtbase | Status: NEW | 0 | 0 |