Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCompleter problem on Mac
Forum Updated to NodeBB v4.3 + New Features

QCompleter problem on Mac

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 716 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jules.dentremont
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • J Offline
        J Offline
        jules.dentremont
        wrote on last edited by
        #3

        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?

        artwawA 1 Reply Last reply
        0
        • J jules.dentremont

          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?

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #4

          @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

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            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

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jules.dentremont
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #7

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

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                1
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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 ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jules.dentremont
                    wrote on last edited by
                    #9

                    @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);
                    }
                    
                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved