QCompleter problem on Mac
-
wrote on 11 Jun 2021, 12:30 last edited by
I recently added a QCompleter to a QComboBox in a legacy application. The code is straightforward:
m_completer = new QCompleter(predefinedComboBox->model(), this); m_completer->setFilterMode(Qt::MatchContains); m_completer->setCaseSensitivity(Qt::CaseInsensitive); m_completer->setCompletionMode(QCompleter::PopupCompletion); predefinedComboBox->setCompleter(m_completer);
On Windows and Linux, this works just as I expected. Typing a few characters shows a popup with the matching completions, and you can click on one to select it. On Mac, though, clicking on the list of completions has no effect. You have to use up and down keys to select a completion, then press Return.
Is this the expected behaviour on Mac? Is it a bug in QCompleter or my code? Is there something I can do differently to get this working?
Using Qt 5.15.0.
-
wrote on 11 Jun 2021, 13:46 last edited by VRonin 6 Nov 2021, 15:26
I don't understand what you are trying to accomplish,
QComboBox
already has a completer, you don't need to set it manually.predefinedComboBox->setAutoCompletion(true);
-
wrote on 11 Jun 2021, 14:43 last edited by
Thanks for the quick response. I'll try that out, but why isn't it documented at https://doc.qt.io/qt-5/qcombobox.html?
-
Thanks for the quick response. I'll try that out, but why isn't it documented at https://doc.qt.io/qt-5/qcombobox.html?
wrote on 11 Jun 2021, 14:52 last edited by@jules-dentremont
'By default, for an editable combo box, a QCompleter that performs case insensitive inline completion is automatically created.'
-
wrote on 11 Jun 2021, 15:27 last edited by
It's actually documented as obsolete. The reason is that the completer is already set up by default and you can call
predefinedComboBox->setCompleter(nullptr);
to disable it -
wrote on 11 Jun 2021, 15:59 last edited by
Thanks, but that is not my main point, which is that setCompletionMode(QCompleter::PopupCompletion) doesn't work properly on Mac. You can't select from the list of completions using a mouse like you can on Windows or Linux.
-
Hi,
Expected behaviour ? No it's not.
Can you provide a minimal compilable example that triggers this behaviour ?
Which version of macOS ?
Did you also check with a more recent version of 5.15 ? -
wrote on 14 Jun 2021, 13:57 last edited by
@SGaist
Here's a compilable program. I don't currently have access to a MacOS build environment, so I can't confirm the behaviour on that system.QT += widgets HEADERS = \ complete.h SOURCES = \ main.cpp \ complete.cpp
main.cpp:
#include <QApplication> #include "complete.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Complete complete; complete.show(); return app.exec(); }
complete.h:
#ifndef COMPLETE_H #define COMPLETE_H #include <QWidget> class QComboBox; class Complete : public QWidget { Q_OBJECT public: Complete(QWidget *parent = 0); private: QComboBox* comboBox; }; #endif
complete.cpp:
#include <QLayout> #include <QComboBox> #include <QCompleter> #include "complete.h" Complete::Complete(QWidget *parent) : QWidget(parent) { QHBoxLayout *layout = new QHBoxLayout(); comboBox = new QComboBox(); comboBox->addItems({"read", "red giant", "refactor", "rifle"}); comboBox->setEditable(true); comboBox->completer()->setCompletionMode(QCompleter::PopupCompletion); layout->addWidget(comboBox); setLayout(layout); setWindowTitle(tr("ComboBox")); resize(200, 200); }
3/9