Results 1 to 3 of 3

Thread: Ensure unique value for column in QTableView

  1. #1
    Join Date
    Jun 2014
    Posts
    30
    Thanks
    4
    Qt products
    Qt5

    Default Ensure unique value for column in QTableView

    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. 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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ensure unique value for column in QTableView

    The model should ensure the data is unique by returning false from setData() call when trying to input non-unique value in an item. Then the delegate in the reimplementation of QAbstractItemDelegate::setModelData() can discover that setting the data failed and can signal it to the editor or wherever you need.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    jmalicke (4th November 2014)

  4. #3
    Join Date
    Jun 2014
    Posts
    30
    Thanks
    4
    Qt products
    Qt5

    Default Re: Ensure unique value for column in QTableView

    Thanks Zen. This is the approach I took.

Similar Threads

  1. Replies: 4
    Last Post: 27th February 2014, 09:42
  2. Set an editable column for QTableView
    By SIFE in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2012, 23:09
  3. Qtableview insert row and column
    By maarvi in forum Newbie
    Replies: 1
    Last Post: 1st July 2011, 09:26
  4. Ensure columns in qtableview uses all available space
    By oysteinpettersen in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2008, 11:28
  5. Fixating column from QTableView ?
    By pinktroll in forum Qt Programming
    Replies: 2
    Last Post: 4th September 2007, 10:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.