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 populate and control the one qcombo box elements from another qcombo box
Forum Updated to NodeBB v4.3 + New Features

how to populate and control the one qcombo box elements from another qcombo box

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 2.0k Views 1 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.
  • V Offline
    V Offline
    veera
    wrote on last edited by
    #1

    Hi All,
    I have two qcombo boxes are there if i have choose one parameter from first qcombo box associated with that parameters only need to display how to do it ...?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Your sentence is a bit broken ;)
      You mean ?
      You have 2 combos
      Combo 1 display
      aaa
      bbb
      cccc
      Combo 2 display
      nothing yet.

      You click on aaa
      now Combo 2 display
      Related to aaa

      Kind of way ?

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

        Your question is very unclear. try giving us an example of what you want to do.

        Spoiler Alert:
        99.9999999% chance the answer is "use the same model for the 2 combo boxes"

        "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
        2
        • V Offline
          V Offline
          veera
          wrote on last edited by veera
          #4

          first qcombox having ticket_printer,bill_acceptor
          second qcombox having slot_admin,smartcard,tckt_in,tckt_out,bill_acceptor_in,bill_acceptor_out

          if i choose bill_acceptor in first qcombo box ,in second qcombo box need to show bill_acceptor_in,bill_acceptor_out only not all in second qcombo box .....

          1 Reply Last reply
          0
          • V Offline
            V Offline
            veera
            wrote on last edited by
            #5

            Hi All,
            Now you got it or shall i send the screen shot of the gui ?

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6
              QAbstarctItemModel* model = new QStandardItemModel(this);
              model->insertColumn(0);
              model->insertRows(0,2);
              auto rootIdx = model->index(0,0);
              model->setData(rootIdx,"ticket_printer");
              model->insertColumn(0,rootIdx);
              model->insertRows(0,4,rootIdx);
              model->setData(model->index(0,0,rootIdx),"slot_admin");
              model->setData(model->index(1,0,rootIdx),"smartcard");
              model->setData(model->index(2,0,rootIdx),"tckt_in");
              model->setData(model->index(3,0,rootIdx),"tckt_out");
              rootIdx = model->index(1,0);
              model->setData(rootIdx,"bill_acceptor");
              model->insertColumn(0,rootIdx);
              model->insertRows(0,2,rootIdx);
              model->setData(model->index(0,0,rootIdx),"bill_acceptor_in");
              model->setData(model->index(1,0,rootIdx),"bill_acceptor_out");
              combo1->setModel(model);
              combo2->setModel(model);
              connect(combo1, QOverload<int>::of(&QComboBox::currentIndexChanged),[=](int idx){combo2->setRootModelIndex(model->index(idx,0)); });
              

              "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
              3
              • V Offline
                V Offline
                veera
                wrote on last edited by
                #7

                @VRonin said in how to populate and control the one qcombo box elements from another qcombo box:

                QAbstarctItemModel* model = new QStandardItemModel(this);

                @VRonin ,
                Thanks a lot ,i have already dialog gui window everything i put into the qcombo boxes.here in this above code you are manually creating it ?

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

                  Yes, Qt Designer doesn't allow to do this so you have to do it manually in the code.

                  That thing goes just after ui->setupUi(this);

                  "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
                  • V veera

                    @VRonin said in how to populate and control the one qcombo box elements from another qcombo box:

                    QAbstarctItemModel* model = new QStandardItemModel(this);

                    @VRonin ,
                    Thanks a lot ,i have already dialog gui window everything i put into the qcombo boxes.here in this above code you are manually creating it ?

                    Taz742T Offline
                    Taz742T Offline
                    Taz742
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      veera
                      wrote on last edited by
                      #10

                      @VRonin
                      okay fine ... i will try this

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

                        An alternative, suggested by @mrjj is to use a QSortFilterProxy model on the second combo to filter out options you don't want to see

                        "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

                        • Login

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