Results 1 to 2 of 2

Thread: contents of QTableView cell are wiped out when one edits via double-click

  1. #1
    Join Date
    Jul 2020
    Posts
    5
    Thanks
    1

    Default contents of QTableView cell are wiped out when one edits via double-click

    I have a QTableView in which some cells contain long strings. When editing a cell via double click, it would be nice to be able to modify the string contents, e.g., add a few characters at the end, without re-typing the whole thing. Is there any way to prevent the contents from being wiped out when one goes into editing mode?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: contents of QTableView cell are wiped out when one edits via double-click

    QAbstractItemView (from which QTableView inherits) has numerous signals that are emitted when the user interacts with cells. clicked(), doubleClicked(), activated(), entered(), and pressed() all send the QModelIndex for the cell. You can use that to retrieve the text of the cell.

    In addition, if you have not implemented the EditRole for your QAbstractItemModel::data() method, then you should implement that role and return the current contents of the cell. That string will be loaded into the editor before it is displayed.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    pfeldman (16th October 2020)

Similar Threads

  1. Replies: 4
    Last Post: 11th January 2014, 04:06
  2. Telling apart single click and double click in QTableView
    By jgirlich in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2013, 15:27
  3. QTableView and changing how a cell displays its contents
    By BitRogue in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2009, 11:18
  4. Clear contents of a QTableView cell before repainting
    By aspidites in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2009, 17:07
  5. Copying contents of QTableView cell to clipboard
    By Conel in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2006, 16:50

Tags for this Thread

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.