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 - Edit Multiple Cells

QTableView - Edit Multiple Cells

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.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.
  • E Offline
    E Offline
    elveatles
    wrote on last edited by
    #1

    How can I allow the user to edit multiple cells in a QTableView?
    I thought about connecting to the model's dataChanged signal, then setting the data for all selected cells. Then I realized that this would create an infinite loop. And I can't just block the dataChanged signal since the view won't get updated if I do.
    So is there some way of doing this? Maybe there's something like a userEdited signal I don't know about.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      There is a SelectionFilter class that should probably be used.
      Did you read this doc:
      "Model/View doc":http://qt-project.org/doc/qt-4.8/modelview.html#3-2-working-with-selections
      On the bottom of the page a lot of examples are placed. Check those out. There will be others who encountered this issue.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • E Offline
        E Offline
        elveatles
        wrote on last edited by
        #3

        Hi,
        Thanks for replying so fast. I Googled for SelectionFilter and could not find anything. I also checked all the examples I could find on QTableView, but none of them allow the user to edit multiple cells. They only edit the last cell that was selected.

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Hi,
          Sorry, it's called: QItemSelectionModel
          So, just a thought, but maybe in your setData function in your model, you read out the QItemSelectionModel items and change the data accordingly.
          Or the other way around, in your view check if multiple items are selected and do a multicall to the setData with the indexes and new value.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • E Offline
            E Offline
            elveatles
            wrote on last edited by
            #5

            How can I avoid an infinite loop? If I listen to the dataChanged signal for when the user has changed the cell, I use setData on the other cells, but setData emits dataChanged so that the view will update, which will call setData again and so on forever.

            qwasder85Q 1 Reply Last reply
            0
            • E elveatles

              How can I avoid an infinite loop? If I listen to the dataChanged signal for when the user has changed the cell, I use setData on the other cells, but setData emits dataChanged so that the view will update, which will call setData again and so on forever.

              qwasder85Q Offline
              qwasder85Q Offline
              qwasder85
              wrote on last edited by qwasder85
              #6

              @elveatles Although this question is very old, for future readers: Use a QSignalBlocker and then manually emit the dataChanged signal once after changing all the values.

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