Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. suggestions for repeating display views
Qt 6.12 LTS is out! See what's new in the release blog

suggestions for repeating display views

Scheduled Pinned Locked Moved Solved Brainstorm
36 Posts 5 Posters 25.2k Views 3 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.
  • VRoninV VRonin

    You have 2 options:
    Do it manually: connect(view->selectionModel(),&QItemSelectionModel::selectionChanged and fill your widgets with data

    or use QDataWidgetMapper like explained here: http://doc.qt.io/qt-5/qdatawidgetmapper.html#setCurrentModelIndex

    mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #27

    @VRonin thanks for the link. I looked at one of the mapper examples (simplewidgetmapper), and I think this is the way to go for me.

    In fact, I'm thinking about changing the entire UI. Instead of separate summary/detail areas, I could provide the user with two lists: one for the MAC address, and one for the device name. When the user makes a selection, all the details area (contained in a grid like the simplewidgetmapper example) would update. The user could then edit the details and press a "commit" button.

    How does this sound so far?

    EDIT:

    So, I've begun an in-place conversion from QTableView to using individual widgets (and QDataWidgetMapper). (I've only implemented 2 fields so far.) I think I must be missing a step, because the fields don't initialize on startup the way they did with the table view.

        mapper = new QDataWidgetMapper(this);
        mapper->setModel(d->getModel());
        mapper->addMapping(ui->comboBoxMacAddr, 0);
        mapper->addMapping(ui->deviceName, 1);
    
        ui->gridLayout->addWidget(ui->labelMacAddr, 0, 0, 1, 1);
        ui->gridLayout->addWidget(ui->comboBoxMacAddr, 0, 1, 1, 1);
        ui->gridLayout->addWidget(ui->labelDevName, 1, 0, 1, 1);
        ui->gridLayout->addWidget(ui->deviceName, 1, 1, 1, 1);
    

    Have I indeed left out a step? It may be noteworthy that, once I select a row in my table (I still have the table active), the update properly affects these fields.

    Thanks...

    VRoninV 1 Reply Last reply
    0
    • mzimmersM mzimmers

      @VRonin thanks for the link. I looked at one of the mapper examples (simplewidgetmapper), and I think this is the way to go for me.

      In fact, I'm thinking about changing the entire UI. Instead of separate summary/detail areas, I could provide the user with two lists: one for the MAC address, and one for the device name. When the user makes a selection, all the details area (contained in a grid like the simplewidgetmapper example) would update. The user could then edit the details and press a "commit" button.

      How does this sound so far?

      EDIT:

      So, I've begun an in-place conversion from QTableView to using individual widgets (and QDataWidgetMapper). (I've only implemented 2 fields so far.) I think I must be missing a step, because the fields don't initialize on startup the way they did with the table view.

          mapper = new QDataWidgetMapper(this);
          mapper->setModel(d->getModel());
          mapper->addMapping(ui->comboBoxMacAddr, 0);
          mapper->addMapping(ui->deviceName, 1);
      
          ui->gridLayout->addWidget(ui->labelMacAddr, 0, 0, 1, 1);
          ui->gridLayout->addWidget(ui->comboBoxMacAddr, 0, 1, 1, 1);
          ui->gridLayout->addWidget(ui->labelDevName, 1, 0, 1, 1);
          ui->gridLayout->addWidget(ui->deviceName, 1, 1, 1, 1);
      

      Have I indeed left out a step? It may be noteworthy that, once I select a row in my table (I still have the table active), the update properly affects these fields.

      Thanks...

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #28

      @mzimmers said in suggestions for repeating display views:

      the fields don't initialize on startup

      What would the expected behaviour be?

      "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
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #29

        I was expecting that the widgets that I mapped to the model would be automatically updated with the model data. (This is how the view table worked.) Could the problem be that I have multiple views setting on the same model? (I still have my view table active.)

        If it looks like I misunderstood the correct use of the mapper, please let me know and I'll make whatever changes necessary.

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

          You just missed the connection.

          @VRonin said in suggestions for repeating display views:

          like explained here: http://doc.qt.io/qt-5/qdatawidgetmapper.html#setCurrentModelIndex

          connect(view->selectionModel(),&QItemSelectionModel::currentRowChanged,mapper,&QDataWidgetMapper::setCurrentModelIndex);

          "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
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #31

            I actually have that connection, and it handles updating the fields once a row is changed. What's missing is the initial setting of the fields before the user selects a row.

            In production, this app is going to be collecting data from remote devices all the time. When it gets the first message (no matter from which device), I'd like to populate the MAC address and device name fields with the information from that message, as it does the view table.

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

              You can call view->selectionModel()->setCurrentIndex(view->model()->index(0,0)); when you insert the first row to populate the linked widgets

              "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
              • VRoninV VRonin

                You have 2 options:
                Do it manually: connect(view->selectionModel(),&QItemSelectionModel::selectionChanged and fill your widgets with data

                or use QDataWidgetMapper like explained here: http://doc.qt.io/qt-5/qdatawidgetmapper.html#setCurrentModelIndex

                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #33

                @VRonin: this solution seems to require the table view. I was hoping to eliminate the table view once I got my individually mapped widgets working. Am I barking up the wrong tree here?

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

                  How would you select which device to show details for?

                  "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
                  • mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #35

                    Hi VRonin - I was thinking to use a combo box for the MAC address.

                    I'm getting the impression that this isn't a great idea, though, so perhaps I'll keep the table after all. The summary area (above the fold) will be read-only, and the details area will permit editing (and a commit).

                    VRoninV 1 Reply Last reply
                    0
                    • mzimmersM mzimmers

                      Hi VRonin - I was thinking to use a combo box for the MAC address.

                      I'm getting the impression that this isn't a great idea, though, so perhaps I'll keep the table after all. The summary area (above the fold) will be read-only, and the details area will permit editing (and a commit).

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #36

                      @mzimmers said in suggestions for repeating display views:

                      I was thinking to use a combo box for the MAC address.

                      Then it's just a small change to the connect statement:
                      connect(combo,QOverload<int>::of(&QComboBox::currentIndexChanged),mapper,&QDataWidgetMapper::setCurrentIndex);

                      "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
                      • Unsolved