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. QCombobox Enable and disable items based selection of item.

QCombobox Enable and disable items based selection of item.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcombobox
7 Posts 2 Posters 989 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
    Mahi_1990
    wrote on last edited by
    #1

    I have many QCombobox 's, I am adding items to all combobox 's in constructor. All items in QCombobox 's are common.
    My requirement is:
    If Item1 is selected in any combobox1 it shouldn't show in all other combobox's. if selection of item is changed combobox1, accordingly updated items in all other combobox's.@SGaist please guide me.

    Thanks in advance for your help.

    JonBJ 1 Reply Last reply
    0
    • M Mahi_1990

      I have many QCombobox 's, I am adding items to all combobox 's in constructor. All items in QCombobox 's are common.
      My requirement is:
      If Item1 is selected in any combobox1 it shouldn't show in all other combobox's. if selection of item is changed combobox1, accordingly updated items in all other combobox's.@SGaist please guide me.

      Thanks in advance for your help.

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

      @Mahi_1990 said in QCombobox Enable and disable items based selection of item.:

      If Item1 is selected in any combobox1 it shouldn't show in all other combobox's. if selection of item is changed combobox1, accordingly updated items in all other combobox's

      So you need to write code to implement just this. Use, say, void QComboBox::currentTextChanged(const QString &text) signal to which you attach a slot that goes removes the text parameter's value from all other comboboxes if that is what you want. Don't forget that you will (presumably) also want to re-add into other comboboxes whatever was previously selected and got removed but is now no longer selected. That might mean you need to keep a record of what all comboboxes start out with initially so that you can restore. Or if you use models for comboboxes' data you might have proxy models which filter out the undesired item in other combos.

      M 1 Reply Last reply
      0
      • JonBJ JonB

        @Mahi_1990 said in QCombobox Enable and disable items based selection of item.:

        If Item1 is selected in any combobox1 it shouldn't show in all other combobox's. if selection of item is changed combobox1, accordingly updated items in all other combobox's

        So you need to write code to implement just this. Use, say, void QComboBox::currentTextChanged(const QString &text) signal to which you attach a slot that goes removes the text parameter's value from all other comboboxes if that is what you want. Don't forget that you will (presumably) also want to re-add into other comboboxes whatever was previously selected and got removed but is now no longer selected. That might mean you need to keep a record of what all comboboxes start out with initially so that you can restore. Or if you use models for comboboxes' data you might have proxy models which filter out the undesired item in other combos.

        M Offline
        M Offline
        Mahi_1990
        wrote on last edited by
        #3

        @JonB
        Thanks for your time reply for me.
        Yes you got it what i am looking for, I need to keep track of all combobox's. Basically, I need unique index from combobox(out of available index's). I prefer to some kind of model can you please point me to right model I should use to get my desired results please.

        Thanks,
        Mahesh

        JonBJ 1 Reply Last reply
        0
        • M Mahi_1990

          @JonB
          Thanks for your time reply for me.
          Yes you got it what i am looking for, I need to keep track of all combobox's. Basically, I need unique index from combobox(out of available index's). I prefer to some kind of model can you please point me to right model I should use to get my desired results please.

          Thanks,
          Mahesh

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

          @Mahi_1990 said in QCombobox Enable and disable items based selection of item.:

          Basically, I need unique index from combobox(out of available index's)

          I don't know what this sentence means.

          For a combobox just containing texts a QStringListModel should suffice.

          If you are saying: you have multiple combos, all show the same items, whenever an item is selected in one of them it cannot be selected in any other (so the combos as a group allow selection of multiple items from the list but each must be unique no duplicates), or something similar. Then you might implement this by having a separate proxy model (with source model being the single shared model) on each one which excludes any of the items selected in any of the others. Otherwise I don't think you can disable or hide an item at the combobox level, so you would have to maintain separate string lists for each one and remove/restore as items get selected/deselected in other combos.

          Unless I misunderstand what you want to achieve :)

          M 1 Reply Last reply
          0
          • JonBJ JonB

            @Mahi_1990 said in QCombobox Enable and disable items based selection of item.:

            Basically, I need unique index from combobox(out of available index's)

            I don't know what this sentence means.

            For a combobox just containing texts a QStringListModel should suffice.

            If you are saying: you have multiple combos, all show the same items, whenever an item is selected in one of them it cannot be selected in any other (so the combos as a group allow selection of multiple items from the list but each must be unique no duplicates), or something similar. Then you might implement this by having a separate proxy model (with source model being the single shared model) on each one which excludes any of the items selected in any of the others. Otherwise I don't think you can disable or hide an item at the combobox level, so you would have to maintain separate string lists for each one and remove/restore as items get selected/deselected in other combos.

            Unless I misunderstand what you want to achieve :)

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

            @JonB
            Thanks for your time.

            db45e21a-0937-480c-92f4-d67a88c795e0-image.png

            What I am trying to implement:
            I have many systems in my hardware configuration, for each system I should provide channel selection using combobox. I can load items to combobox QStringListModel no problem here(In Image you see all items are manually, I have to upgrade this to load it from QStringListModel )
            What I am looking for is if user selects channel 1 for xx system, for other systems channel 1 should not visible, but it should be there in the list, because I am using index as channel number in downstream logics.

            JonBJ 1 Reply Last reply
            0
            • M Mahi_1990

              @JonB
              Thanks for your time.

              db45e21a-0937-480c-92f4-d67a88c795e0-image.png

              What I am trying to implement:
              I have many systems in my hardware configuration, for each system I should provide channel selection using combobox. I can load items to combobox QStringListModel no problem here(In Image you see all items are manually, I have to upgrade this to load it from QStringListModel )
              What I am looking for is if user selects channel 1 for xx system, for other systems channel 1 should not visible, but it should be there in the list, because I am using index as channel number in downstream logics.

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

              @Mahi_1990
              And I have suggested the two ways you might do this:

              • Either keep a separate model/list in each combobox so that you can remove and re-add items as they are selected/deselected in other combos; or

              • Impose a QAbstractProxyModel (will be a QIdentityProxyModel with a little configuration) on each combo sitting atop the QStringList model which excludes any item which has been selected in all combos other than itself.

              M 1 Reply Last reply
              0
              • JonBJ JonB

                @Mahi_1990
                And I have suggested the two ways you might do this:

                • Either keep a separate model/list in each combobox so that you can remove and re-add items as they are selected/deselected in other combos; or

                • Impose a QAbstractProxyModel (will be a QIdentityProxyModel with a little configuration) on each combo sitting atop the QStringList model which excludes any item which has been selected in all combos other than itself.

                M Offline
                M Offline
                Mahi_1990
                wrote on last edited by
                #7

                @JonB
                I am new with qt.
                I am not able to implement this, any working sample code will be helpful for me.

                Thanks in advance for help.

                Thanks,
                Mahesh

                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