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. editable qcombobox entries
Forum Updated to NodeBB v4.3 + New Features

editable qcombobox entries

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 5 Posters 4.8k 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i have an editable qcombobox, and i want to insert only entries which i need to (actually, only "valid" entries). how can i do that?

    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #2

      What is the criteria for an entry being "valid?"

      1 Reply Last reply
      0
      • U Offline
        U Offline
        user4592357
        wrote on last edited by user4592357
        #3

        that's some logic i've implemented

        JonBJ mzimmersM 2 Replies Last reply
        0
        • U user4592357

          that's some logic i've implemented

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

          @user4592357
          Then only insert those entries which pass your logic?? You choose which entries to insert, so we don't really know what you mean.

          1 Reply Last reply
          0
          • U user4592357

            that's some logic i've implemented

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @user4592357 I'm not sure I understand, but here's how I add entries to a combo box:

                QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts();
                QList<QSerialPortInfo>::iterator p;
            
                // clear the list first.
                clear();
            
                for (p = list.begin(); p != list.end(); ++p)
                {
            // your logic would go here: if (this entry passes my criteria, add it)
                    addItem(p->portName());
                }
            
            1 Reply Last reply
            1
            • aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by aha_1980
              #6

              @user4592357: I got it - editable combobox. you can add an input validator to the combobox' lineEdit() [1]. please see the help for details, I only have the phone at hand.

              [1] http://doc.qt.io/qt-5/qcombobox.html#lineEdit

              Qt has to stay free or it will die.

              JonBJ 1 Reply Last reply
              1
              • aha_1980A aha_1980

                @user4592357: I got it - editable combobox. you can add an input validator to the combobox' lineEdit() [1]. please see the help for details, I only have the phone at hand.

                [1] http://doc.qt.io/qt-5/qcombobox.html#lineEdit

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

                @aha_1980
                So he didn't mean "insert entries", he meant "validate text if user chooses to type something" ?

                aha_1980A 1 Reply Last reply
                0
                • JonBJ JonB

                  @aha_1980
                  So he didn't mean "insert entries", he meant "validate text if user chooses to type something" ?

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @JNBarchan thats how i read the question :)

                  Qt has to stay free or it will die.

                  mzimmersM 1 Reply Last reply
                  0
                  • aha_1980A aha_1980

                    @JNBarchan thats how i read the question :)

                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #9

                    @aha_1980 as did I. So, do I understand your solution to mean that the OP would have to implement his own editor in order to add a validator?

                    JonBJ 1 Reply Last reply
                    0
                    • mzimmersM mzimmers

                      @aha_1980 as did I. So, do I understand your solution to mean that the OP would have to implement his own editor in order to add a validator?

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

                      @mzimmers
                      No, just add validator to existing QComboBox::lineEdit().

                      mzimmersM 1 Reply Last reply
                      3
                      • JonBJ JonB

                        @mzimmers
                        No, just add validator to existing QComboBox::lineEdit().

                        mzimmersM Offline
                        mzimmersM Offline
                        mzimmers
                        wrote on last edited by
                        #11

                        @JNBarchan OK, I get it now...that's a pretty cool feature that I wasn't aware of. Qt is awesome...

                        1 Reply Last reply
                        0
                        • U Offline
                          U Offline
                          user4592357
                          wrote on last edited by
                          #12

                          ugh, so much had been going on while i wasn't here...

                          well, what i meant was, i have an editable combo box, and the user inputs something. i get the input and check if it's valid, then i add the string to the combo via addItem(). but it adds every string typed in. so maybe i need something to execute on else branch? like, delete this last added entry? but that's an ugly solution tbh

                          JonBJ 1 Reply Last reply
                          0
                          • U user4592357

                            ugh, so much had been going on while i wasn't here...

                            well, what i meant was, i have an editable combo box, and the user inputs something. i get the input and check if it's valid, then i add the string to the combo via addItem(). but it adds every string typed in. so maybe i need something to execute on else branch? like, delete this last added entry? but that's an ugly solution tbh

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

                            @user4592357 said in editable qcombobox entries:

                            i get the input and check if it's valid, then i add the string to the combo via addItem(). but it adds every string typed in.

                            Well if your code is wrong for the check validity call, or it passes as valid when it shouldn't, or you haven't actually attached the validator to the text correctly, that would behave as you describe! It's a bit hard to know if only you can see the code....

                            mzimmersM 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @user4592357 said in editable qcombobox entries:

                              i get the input and check if it's valid, then i add the string to the combo via addItem(). but it adds every string typed in.

                              Well if your code is wrong for the check validity call, or it passes as valid when it shouldn't, or you haven't actually attached the validator to the text correctly, that would behave as you describe! It's a bit hard to know if only you can see the code....

                              mzimmersM Offline
                              mzimmersM Offline
                              mzimmers
                              wrote on last edited by
                              #14

                              @JNBarchan it seems like you could prevent the edited string from being automatically added using the QComboBox::NoInsert option for enum QComboBox::InsertPolicy. I'm not sure, though, how you'd obtain the string the user created. If you could, you could of course validate and possibly insert it programmatically.

                              1 Reply Last reply
                              0
                              • U Offline
                                U Offline
                                user4592357
                                wrote on last edited by
                                #15

                                i had tried setInsertPolicy, but that won't even let me get press enter, i couldn't get the text cause the focus was just stuck on line edit. no everything is okay with validation, for wrong input i print something to the console, so the else branch of validation works, but the string still gets added.

                                jsulmJ 1 Reply Last reply
                                0
                                • U user4592357

                                  i had tried setInsertPolicy, but that won't even let me get press enter, i couldn't get the text cause the focus was just stuck on line edit. no everything is okay with validation, for wrong input i print something to the console, so the else branch of validation works, but the string still gets added.

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @user4592357 Did you try what @aha_1980 suggested?

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • U Offline
                                    U Offline
                                    user4592357
                                    wrote on last edited by user4592357
                                    #17

                                    i don't need that, i just need to get all inputs, and choose which one i wanna add, there's no really a validator needed in my case. i'm accepting file paths, i only wanna add the file path to the combo if a file with such path exists

                                    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