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. Multiple QComboBoxes, I want to change the selection of a combobox based on the selection of another
QtWS25 Last Chance

Multiple QComboBoxes, I want to change the selection of a combobox based on the selection of another

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.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.
  • R Offline
    R Offline
    RATyson
    wrote on last edited by
    #1

    I am brand new to QT. Learning on the fly.

    I am designing a configuration wizard and have run into a dilema.

    I have 8 QComboBoxes that contain the same list of selections from a model (subclassed QAbstractListModel).

    The combo boxes are used to select devices attached to com ports.

    If the user selects one item, I need to make sure that any other combo box that has that same selection changes to index 0 (a blank selection as defined in the model). This would seem to be more user friendly than requiring the user to first go back and de-select a previous selection, then come back and make the current selection.

    Basically, there can be no repeated selections across the 8 combo boxes.

    Currently, the only relationship between these 8 combo boxes are that they are common to a single QHBoxLayout.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Just off the top of my head...

      You could create a helper class that knows about all of the combo boxes (perhaps keeps a list of pointers to them) and connect each of their currentIndexChanged signals to it. It could then iterate over all of the other boxes and clear any that match the same value.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RATyson
        wrote on last edited by
        #3

        Thanks mlong!

        I was in the "Can't see the forest for the trees" loop.

        I was also focused on finding some magical way to do this through the model that holds the values used in the combo boxes.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RATyson
          wrote on last edited by
          #4

          In looking at this problem again. I think I am going to have to rethink my layout.

          Currently, these comboboxes are not contained in a grid or table, they are just created in a layout.

          In order to be able to know which combobox sent the signal, I am going to have to lay these combo boxes out in a grid or table widget, and use the signalMapper. That way I can get the row/col of who sent it, get the index or QString of that combobox, and check the others for their settings.

          Does this sound correct? Or am I missing something again?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            Using a layout or grid or table widget is independent of using a QSignalMapper. How you generate an id is up to you. You could just as easily manually number your QComboBoxes as (0..n)

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            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