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 create an editable combo box
Forum Updated to NodeBB v4.3 + New Features

how to create an editable combo box

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 3 Posters 7.6k 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.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by
    #1

    I want to create a combo box which has some default value ( for example my default are 4000,5000,6000) , (my range is between 4000 - 5000 ) and user should be able to insert any value in between these . Whether it can be done ?

    J.HilkJ ManiRonM 2 Replies Last reply
    0
    • ManiRonM ManiRon

      I want to create a combo box which has some default value ( for example my default are 4000,5000,6000) , (my range is between 4000 - 5000 ) and user should be able to insert any value in between these . Whether it can be done ?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @ManiRon
      comboboxes are editable

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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      ManiRonM 1 Reply Last reply
      2
      • ManiRonM ManiRon

        I want to create a combo box which has some default value ( for example my default are 4000,5000,6000) , (my range is between 4000 - 5000 ) and user should be able to insert any value in between these . Whether it can be done ?

        ManiRonM Offline
        ManiRonM Offline
        ManiRon
        wrote on last edited by
        #3

        @ManiRon I used combo box set editable to true. but how to make it accept data within that range

        aha_1980A 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @ManiRon
          comboboxes are editable

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

          ManiRonM Offline
          ManiRonM Offline
          ManiRon
          wrote on last edited by
          #4

          @J.Hilk Yes Sir i used it and it worked but how to make it accept data within that range

          1 Reply Last reply
          0
          • ManiRonM ManiRon

            @ManiRon I used combo box set editable to true. but how to make it accept data within that range

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

            @ManiRon By setting a Validator

            Qt has to stay free or it will die.

            ManiRonM 1 Reply Last reply
            2
            • aha_1980A aha_1980

              @ManiRon By setting a Validator

              ManiRonM Offline
              ManiRonM Offline
              ManiRon
              wrote on last edited by
              #6

              @aha_1980 said in how to create an editable combo box:

              By setting a Validator

              any sample if possible sir ?

              aha_1980A 1 Reply Last reply
              0
              • ManiRonM ManiRon

                @aha_1980 said in how to create an editable combo box:

                By setting a Validator

                any sample if possible sir ?

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

                @ManiRon The internet is full of examples. From your description, you could probably use https://doc.qt.io/qt-5/qintvalidator.html

                Qt has to stay free or it will die.

                ManiRonM 1 Reply Last reply
                1
                • aha_1980A aha_1980

                  @ManiRon The internet is full of examples. From your description, you could probably use https://doc.qt.io/qt-5/qintvalidator.html

                  ManiRonM Offline
                  ManiRonM Offline
                  ManiRon
                  wrote on last edited by ManiRon
                  #8

                  @aha_1980 i have a doubt sir , when should i apply this validator , cause i applied in my mainwindow constructor, its throwing error

                  aha_1980A 1 Reply Last reply
                  0
                  • ManiRonM ManiRon

                    @aha_1980 i have a doubt sir , when should i apply this validator , cause i applied in my mainwindow constructor, its throwing error

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

                    @ManiRon

                    There is an example with line edits here: https://wiki.qt.io/QIntValidator

                    It should be very similar with combo box.

                    cause i applied in my mainwindow constructor, its throwing error

                    With such imprecise error descriptions you will likely get imprecise answers.

                    Qt has to stay free or it will die.

                    ManiRonM 3 Replies Last reply
                    3
                    • aha_1980A aha_1980

                      @ManiRon

                      There is an example with line edits here: https://wiki.qt.io/QIntValidator

                      It should be very similar with combo box.

                      cause i applied in my mainwindow constructor, its throwing error

                      With such imprecise error descriptions you will likely get imprecise answers.

                      ManiRonM Offline
                      ManiRonM Offline
                      ManiRon
                      wrote on last edited by
                      #10

                      @aha_1980 whether QIntValidator restricts user while entering the data itself ?

                      aha_1980A 1 Reply Last reply
                      0
                      • aha_1980A aha_1980

                        @ManiRon

                        There is an example with line edits here: https://wiki.qt.io/QIntValidator

                        It should be very similar with combo box.

                        cause i applied in my mainwindow constructor, its throwing error

                        With such imprecise error descriptions you will likely get imprecise answers.

                        ManiRonM Offline
                        ManiRonM Offline
                        ManiRon
                        wrote on last edited by
                        #11

                        @aha_1980 why because after setting validator , it accepts data less than the range

                        J.HilkJ 1 Reply Last reply
                        0
                        • aha_1980A aha_1980

                          @ManiRon

                          There is an example with line edits here: https://wiki.qt.io/QIntValidator

                          It should be very similar with combo box.

                          cause i applied in my mainwindow constructor, its throwing error

                          With such imprecise error descriptions you will likely get imprecise answers.

                          ManiRonM Offline
                          ManiRonM Offline
                          ManiRon
                          wrote on last edited by
                          #12

                          @aha_1980 This is my code

                          #include "mainwindow.h"
                          #include "ui_mainwindow.h"
                          #include"QInputMethodEvent"
                          #include"QIntValidator"

                          MainWindow::MainWindow(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::MainWindow)
                          {
                          ui->setupUi(this);
                          ui->comboBox->setEditable(true);
                          ui->comboBox->setValidator(new QIntValidator(4400, 5000, this));
                          ui->lineEdit->setValidator(new QIntValidator(4400, 5000, this));

                          }

                          MainWindow::~MainWindow()
                          {
                          delete ui;
                          }

                          1 Reply Last reply
                          0
                          • ManiRonM ManiRon

                            @aha_1980 whether QIntValidator restricts user while entering the data itself ?

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

                            @ManiRon There seems indeed be some problems with the lower bound. I didn't manage to input number greater than the upper limit, but for the lower limit it did not work (e.g. it allows zero).

                            I think the best would be to write your own validator based on QValidator in that case. That gives you full control.

                            Qt has to stay free or it will die.

                            1 Reply Last reply
                            0
                            • ManiRonM ManiRon

                              @aha_1980 why because after setting validator , it accepts data less than the range

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on last edited by
                              #14

                              @ManiRon
                              how much less ? if you only enter 3 digits, than that is an intermediate state and has to be an acceptable input.

                              4300 for example should not be possible.


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              ManiRonM 1 Reply Last reply
                              0
                              • J.HilkJ J.Hilk

                                @ManiRon
                                how much less ? if you only enter 3 digits, than that is an intermediate state and has to be an acceptable input.

                                4300 for example should not be possible.

                                ManiRonM Offline
                                ManiRonM Offline
                                ManiRon
                                wrote on last edited by ManiRon
                                #15

                                @J.Hilk Its accepting from 0 to 5000 sir , But not more than 5000. But i want it to accept only from the range of 4400 to 5000

                                J.HilkJ 1 Reply Last reply
                                0
                                • ManiRonM ManiRon

                                  @J.Hilk Its accepting from 0 to 5000 sir , But not more than 5000. But i want it to accept only from the range of 4400 to 5000

                                  J.HilkJ Offline
                                  J.HilkJ Offline
                                  J.Hilk
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  @ManiRon
                                  nope, just tested it.

                                  If you write anything below 4400 the entry is not added to the combobox, if you write anything in the valid range, it is added and if you try to go above the maximum it is also not added to the combobox.

                                  AFAIK working as intended.

                                  If you wan't to limit your textinput of the combobox, then that's a different matter and even more complicated.


                                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                  Q: What's that?
                                  A: It's blue light.
                                  Q: What does it do?
                                  A: It turns blue.

                                  ManiRonM 1 Reply Last reply
                                  2
                                  • J.HilkJ J.Hilk

                                    @ManiRon
                                    nope, just tested it.

                                    If you write anything below 4400 the entry is not added to the combobox, if you write anything in the valid range, it is added and if you try to go above the maximum it is also not added to the combobox.

                                    AFAIK working as intended.

                                    If you wan't to limit your textinput of the combobox, then that's a different matter and even more complicated.

                                    ManiRonM Offline
                                    ManiRonM Offline
                                    ManiRon
                                    wrote on last edited by ManiRon
                                    #17

                                    @J.Hilk ya i will be entering the text in the combo box as i have made it editable . while entering the text only i face this issue . It accepts from 0 to 5000

                                    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