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. Ensure unique value for column in QTableView
Forum Updated to NodeBB v4.3 + New Features

Ensure unique value for column in QTableView

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

    I have implemented a custom QTableView and QAbstractTableModel. The QTableView uses the Qt-default text line edit delegate for manipulating string data. I would like to ensure that, after submitting an edit (pressing enter), the string is unique for its column. If another row has the same value for that column, the edit will be rejected, perhaps with a popup box, and then the text line edit will be programmatically put back into edit mode so the user can try again.

    I have thought about using a custom delegate and possibly communicating between the delegate and the table view via signal and slots. The delegate could ensure that the value is unique inside setModelData(). To do this it would have to be injected with knowledge about the other columns. If the value is not unique, the delegate could emit a signal that the table view would pick up; something like "notUniqueTryAgain()". Inside that slot the table would pop up a message and then call edit() on the cell. Is this the right way to go?

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

      Hi,

      Maybe also a custom validator on the QLineEdit that will check check that what you write is "legal".

      You don't need to inject anything in setModelData, you can access the other values of the model through the given index parameter.

      Now the question is, should setModelData do the check or the model itself ?

      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

      • Login

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