Nominate our 2022 Qt Champions!

QCompleter problem on Mac



  • 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.



  • 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);



  • 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?



  • @jules-dentremont

    'By default, for an editable combo box, a QCompleter that performs case insensitive inline completion is automatically created.'

    https://doc.qt.io/qt-5/qcombobox.html#setCompleter



  • 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



  • 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.



  • Unfortunately I don't have a Mac to test. @SGaist you are renown for Mac stuff, could you confirm?


  • Lifetime Qt Champion

    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 ?



  • @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.

    complete.pro:

    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);
    }
    

Log in to reply