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: How does one prohibit changing rows when data is lacking in one of the columns?
Forum Updated to NodeBB v4.3 + New Features

QTableView: How does one prohibit changing rows when data is lacking in one of the columns?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 635 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    I can connect to the currentRowChanged signal of the table view's QItemSelectionModel, but this is only emitted AFTER the user clicks on a cell in a different row or column of the table view. If the new column is in the same row being edited, this is OK; but I would like to cancel any row change if data is missing from one of the columns in the row currently being edited.

    The underlying model for the table view has two columns which can both be edited. Initially, the table can be empty. The user can add a new row by clicking a button, and rows can be removed by clicking a different button. Both columns in the new row should then be filled in by the user before adding another row. I can prohibit adding a new row by code running in the slot connected to the button's clicked signal, checking the data in the existing row, but the user can also click on a previous row without completing the new row. This kind of row change should also be prevented.

    What is the standard approach to this presumably very common scenario?

    JonBJ 1 Reply Last reply
    1
    • R Robert Hairgrove

      I can connect to the currentRowChanged signal of the table view's QItemSelectionModel, but this is only emitted AFTER the user clicks on a cell in a different row or column of the table view. If the new column is in the same row being edited, this is OK; but I would like to cancel any row change if data is missing from one of the columns in the row currently being edited.

      The underlying model for the table view has two columns which can both be edited. Initially, the table can be empty. The user can add a new row by clicking a button, and rows can be removed by clicking a different button. Both columns in the new row should then be filled in by the user before adding another row. I can prohibit adding a new row by code running in the slot connected to the button's clicked signal, checking the data in the existing row, but the user can also click on a previous row without completing the new row. This kind of row change should also be prevented.

      What is the standard approach to this presumably very common scenario?

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

      @Robert-Hairgrove
      Since I cannot see how to do this either: would having your currentRowChanged slot check whether its previous row is incompletely-edited and call select(previous) be viable?

      The nearest I can find to your (reasonable) question is https://stackoverflow.com/questions/50218443/qtreeview-how-to-abort-selection-change. Have a read through, I think you'll see it's taking my suggested approach, see how it relates to yours. Similarish https://stackoverflow.com/questions/54233639/qtableview-prevent-a-user-from-navigating-away-from-a-spesific-row. It looks like you cannot cancel the change, you have to revert to the previous (yuck), and then they describe workarounds to make that change back happen just after it has changed row, since apparently it will not work if called while still inside the slot....

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

        What model are you using?
        I would discourage you to implement what you describe as it may become very frustrating for the user. Imagine if the guy wants to copy a value from a cell above to fill in the data of a new row

        "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

        JonBJ 1 Reply Last reply
        2
        • VRoninV VRonin

          What model are you using?
          I would discourage you to implement what you describe as it may become very frustrating for the user. Imagine if the guy wants to copy a value from a cell above to fill in the data of a new row

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

          @VRonin
          Agreed. Then how can you put a QTableView into "row edit mode", and not allow it to leave that until all columns are valid?

          VRoninV 1 Reply Last reply
          0
          • JonBJ JonB

            @VRonin
            Agreed. Then how can you put a QTableView into "row edit mode", and not allow it to leave that until all columns are valid?

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

            @JonB I wouldn't reinvent the wheel and just do what MS Access and Libre Office do. See Insert Proxy Model of this library

            "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
            5
            • R Offline
              R Offline
              Robert Hairgrove
              wrote on last edited by
              #6

              Thanks, everyone. I think I will do this differently. The table view is actually part of a custom editor which is opened on a cell in another table view. I will do validation only when I commit the data as an entire table. Seems like a much cleaner design and more simple to implement.

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved