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. Use of several QCombobox that work together

Use of several QCombobox that work together

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 551 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.
  • A Offline
    A Offline
    AlexKrammer
    wrote on last edited by
    #1

    Im trying to use several comboboxes who are linked together.

    I have 5 sensors and each one have a own address.

    It looks like that:
    Capture.JPG

    On the right are 5 combo boxes with selectable items: N.C. (not connected),1,2,3,4 and 5.

    e.g. If Line 1 is set to 1, the item 1 should be removed from line 2-5

    Picture:
    Screenshot (7).png

    So if on line 1 selected 1 and on line 3 selected 2. On line 5 eg. there should only be N.C.,3,4 and 5. So no double choice.

    I just tried it like that, but it dont dependent on the other comboboxes.:

    for(int i = 1 ; i <= Initialisationlist.count() ; i++)
        {
            QLabel * label   = this->findChild<QLabel   *>("label_"+QString::number(i));
            QComboBox * CBox = this->findChild<QComboBox*>("CBoxSensor_"+QString::number(i));
    
            if(label)
            {
                CBox->clear();
                CBox->addItem("N.C.");
                label->setText(Initialisationlist.at(i-1));
                for (int x=1 ; x <= Initialisationlist.count(); x++)
                {
                    CBox->addItem(QString::number(x));
                }
                CBox->setCurrentIndex(0);
            }
        }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One possible way to do that is to use a common model that contains all the data and then use a QFilterProxyModel for each QComboBox where you filter out the already selected values.

      The other solution is to regenerate the content of all the combo boxes based on the value that just changed and all the non NC.

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

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        One possible way to do that is to use a common model that contains all the data and then use a QFilterProxyModel for each QComboBox where you filter out the already selected values.

        The other solution is to regenerate the content of all the combo boxes based on the value that just changed and all the non NC.

        A Offline
        A Offline
        AlexKrammer
        wrote on last edited by AlexKrammer
        #3

        @SGaist whats does a common model mean? And how could i use it?
        And use one common model for all combo boxes Informations and then use QFilterProxyModel for each filter for the boxes

        Pablo J. RoginaP 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you know what a model is ?
          Did you check the QSortFilterProxyModel documentation ?

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

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Do you know what a model is ?
            Did you check the QSortFilterProxyModel documentation ?

            A Offline
            A Offline
            AlexKrammer
            wrote on last edited by
            #5

            @SGaist im soo sorry to be such a noob:D
            I really dont know what a model or even a common model is. What i have to read about? Do you mean QAbstractItemModel or what i have to read about?

            1 Reply Last reply
            0
            • A AlexKrammer

              @SGaist whats does a common model mean? And how could i use it?
              And use one common model for all combo boxes Informations and then use QFilterProxyModel for each filter for the boxes

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @AlexKrammer as @SGaist suggested, you may want to provide a custom model for your QComboBox objects.

              Check these posts here and here for a possible way to go.

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              A 1 Reply Last reply
              1
              • Pablo J. RoginaP Pablo J. Rogina

                @AlexKrammer as @SGaist suggested, you may want to provide a custom model for your QComboBox objects.

                Check these posts here and here for a possible way to go.

                A Offline
                A Offline
                AlexKrammer
                wrote on last edited by
                #7

                @Pablo-J-Rogina
                I understand. But one last question.
                Every time when i change one combobox i have to reload all other comboboxes with their items?

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

                  It's going to depend on the solution you choose.

                  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

                  • Login

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