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. How to get the text of a complete in a combobox
Qt 6.11 is out! See what's new in the release blog

How to get the text of a complete in a combobox

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 2.5k Views
  • 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.
  • M Offline
    M Offline
    Morado
    wrote on last edited by
    #1

    Hi Can someone help me with my problem, I have a combobox that I fill with a QList and now I have generated a search engine with the help of the QCompleter, so far everything is fine, but I have edited it to make it visually more attractive, and it worked correctly until I have trouble selecting with the mouse one of the options that the QCompleter threw at me and the selection does not respect me, it only respects me if I give an Enter with the keyboard, but only for a moment, someone could help me solve my problem.

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
     qApp->setStyleSheet("QAbstractItemView#completerPopup {font: 15pt ;color: rgb(255, 255, 255);}");
    }
    
        QCompleter *completer = new QCompleter(list, this);
        completer->setFilterMode(Qt::MatchContains);
        completer->setCaseSensitivity(Qt::CaseInsensitive);
        completer->popup()->setObjectName("completerPopup");
        ui->cobobox->setCompleter(completer);
    

    I manage to make it work but I have to remove some lines of code that are the ones that help me edit the QCompleter as Pupop.

        QCompleter *completer = new QCompleter(list, this);
        completer->setFilterMode(Qt::MatchContains);
        completer->setCaseSensitivity(Qt::CaseInsensitive);
        ui->cobobox->setCompleter(completer);
    

    The error it throws when I select is the following
    Setting a QCompleter on non-editable QComboBox is not allowed.

    JonBJ 1 Reply Last reply
    1
    • M Morado

      Hi Can someone help me with my problem, I have a combobox that I fill with a QList and now I have generated a search engine with the help of the QCompleter, so far everything is fine, but I have edited it to make it visually more attractive, and it worked correctly until I have trouble selecting with the mouse one of the options that the QCompleter threw at me and the selection does not respect me, it only respects me if I give an Enter with the keyboard, but only for a moment, someone could help me solve my problem.

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
       qApp->setStyleSheet("QAbstractItemView#completerPopup {font: 15pt ;color: rgb(255, 255, 255);}");
      }
      
          QCompleter *completer = new QCompleter(list, this);
          completer->setFilterMode(Qt::MatchContains);
          completer->setCaseSensitivity(Qt::CaseInsensitive);
          completer->popup()->setObjectName("completerPopup");
          ui->cobobox->setCompleter(completer);
      

      I manage to make it work but I have to remove some lines of code that are the ones that help me edit the QCompleter as Pupop.

          QCompleter *completer = new QCompleter(list, this);
          completer->setFilterMode(Qt::MatchContains);
          completer->setCaseSensitivity(Qt::CaseInsensitive);
          ui->cobobox->setCompleter(completer);
      

      The error it throws when I select is the following
      Setting a QCompleter on non-editable QComboBox is not allowed.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Morado said in How to get the text of a complete in a combobox:

      Setting a QCompleter on non-editable QComboBox is not allowed.

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

      This property holds whether the combo box can be edited by the user

      By default, this property is false. The effect of editing depends on the insert policy.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Morado
        wrote on last edited by
        #3

        Thanks for responding so quickly,I try this

        ui->combobox->setInsertPolicy(QComboBox::InsertAtCurrent);
        

        And with all its possible combinations:

        QComboBox::InsertAtTop
        QComboBox::InsertAtBottom
        QComboBox::InsertAfterCurrent
        QComboBox::InsertBeforeCurrent
        QComboBox::InsertAlphabetically
        

        But it did not give me any favorable results.
        Or is it that I'm wrong about something?

        JonBJ 1 Reply Last reply
        0
        • M Morado

          Thanks for responding so quickly,I try this

          ui->combobox->setInsertPolicy(QComboBox::InsertAtCurrent);
          

          And with all its possible combinations:

          QComboBox::InsertAtTop
          QComboBox::InsertAtBottom
          QComboBox::InsertAfterCurrent
          QComboBox::InsertBeforeCurrent
          QComboBox::InsertAlphabetically
          

          But it did not give me any favorable results.
          Or is it that I'm wrong about something?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Morado
          Did you do the setEditable(true) per the link? That is what makes the QComboBox editable. setInsertPolicy() is irrelevant.

          The default QComboBox is just a dropdown non-editable list. It does not accept text input, so a QCompleter makes no sense. You have to set it editable to get an edit widget and a completer.

          M 2 Replies Last reply
          0
          • JonBJ JonB

            @Morado
            Did you do the setEditable(true) per the link? That is what makes the QComboBox editable. setInsertPolicy() is irrelevant.

            The default QComboBox is just a dropdown non-editable list. It does not accept text input, so a QCompleter makes no sense. You have to set it editable to get an edit widget and a completer.

            M Offline
            M Offline
            Morado
            wrote on last edited by Morado
            #5

            @JonB
            I had just done it before you answered me, and it doesn't affect it in the same way.

            ui->combobox->setEditable(true);
            ui->combobox->setCompleter(completer);
            

            or I am doing something wrong again?

            1 Reply Last reply
            0
            • JonBJ JonB

              @Morado
              Did you do the setEditable(true) per the link? That is what makes the QComboBox editable. setInsertPolicy() is irrelevant.

              The default QComboBox is just a dropdown non-editable list. It does not accept text input, so a QCompleter makes no sense. You have to set it editable to get an edit widget and a completer.

              M Offline
              M Offline
              Morado
              wrote on last edited by
              #6

              @JonB

              I was reviewing the documentation and enabling setEditable only allows me to write to the Combobox and I have already achieved this from the GUI, my problem is that it does not allow me to select from the popup with the mouse. But with keyboard yes.

              JonBJ 1 Reply Last reply
              0
              • M Morado

                @JonB

                I was reviewing the documentation and enabling setEditable only allows me to write to the Combobox and I have already achieved this from the GUI, my problem is that it does not allow me to select from the popup with the mouse. But with keyboard yes.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Morado
                It was you who wrote

                The error it throws when I select is the following

                Setting a QCompleter on non-editable QComboBox is not allowed.

                That's all I know.

                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