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. QTableView set mapper current index on row click
Forum Updated to NodeBB v4.3 + New Features

QTableView set mapper current index on row click

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.5k 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.
  • P Offline
    P Offline
    Panoss
    wrote on last edited by
    #1

    I want, when a row of the table is clicked, to set mapper->currentIndex at the selected record.
    How can do this?
    The mapper is a data mapper and the model of the table QSqlRelationalTableModel.

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

      Hi,

      QDataWidgetMapper::setCurrentModelIndex looks like a better option.

      See the sample code from the function's documentation. It looks like what you might be trying to accomplish.

      Hope it helps

      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
      1
      • P Offline
        P Offline
        Panoss
        wrote on last edited by
        #3

        Works perfectly SGaist!!
        But now I have another issue, I want to clear the mapped fields setting currentIndex to -1, I tried

        mapper->setCurrentIndex(-1);
        

        Also with:

        mapper->submit();
        

        But the mapped fields (two QTextBoxes) don't get cleared!

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

          AFAIK, you can't do it like that. The QDataWidgetMapper won't change anything if you path an invalid index value.

          If you want it empty, you're likely going to have to reset the mappings.

          However that doesn't sound clean, why do you need it to be in such an "invalid" state ?

          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
          • P Offline
            P Offline
            Panoss
            wrote on last edited by Panoss
            #5

            I have a combo, a table, and a textbox.
            TextBox is mapped to a field by the mapper.

            I select an option from the combo, the table gets refreshed with new records, depending on the option selected in the combo.
            I click on a row in the table, and mapper 's current index goes to the selected record(with the code you suggested).
            So the textbox gets the appropriate data.

            I select another option from the combo, the table gets refreshed.
            I have not, yet, clicked on the table, no row is selected.
            But the textbox still has the same content.
            I want it to be empty.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Panoss
              wrote on last edited by Panoss
              #6

              Maybe, remove mapping from the textbox and reattach it when needed?
              What do you think?

              EDIT: I dit it this way, it works.
              But I don't know if it's the best way.

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

                can't you just call TextBox::clear() ?

                "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

                P 1 Reply Last reply
                2
                • VRoninV VRonin

                  can't you just call TextBox::clear() ?

                  P Offline
                  P Offline
                  Panoss
                  wrote on last edited by
                  #8

                  @VRonin you 're right, this is enough.

                  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