Results 1 to 3 of 3

Thread: How to Add Text to Editor in QTableView

  1. #1
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to Add Text to Editor in QTableView

    Hi,

    I've created an app that uses QTableView to display data (version 4.5.x). It is connected to a class derived from QAbstractTableModel. It saves and displays data, allows the data to be edited, uses signals and slots, etc. Everything works fine, but I noticed that if you double click on a cell the editor will start, but any data that was in the cell is gone. It is still in the model until you save it, but the cell itself is blank.

    I thought it would be nice to display the current data in the editor so if you only wanted to change it a little you wouldn't have to retype everything. But I can not figure out how to do this.

    I added a signal function to pick up the double click on the table cell, got the data from the model and... have no way to enter it into the editor so it is visible. I can find no way to set the value of the cell.

    I thought I would have to use a custom delegate, but I can't figure out how that would work. setEditorData sounded like it could help, but no. It is not designed to help me with this task.

    Just to be clear: I have no trouble typing in text and saving it and displaying it later. I just want to double click on a cell and have the current text be displayed in the editor before I start making changes.

    I hope someone can help me figure out how to do this, because I don't have any idea.

    Thanks

  2. #2
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to Add Text to Editor in QTableView

    Does your model return data for Qt::EditRole? This data is used in editors as the default when you start edition. Just return the same what you return for Qt:isplayRole and it will work fine.

  3. #3
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to Add Text to Editor in QTableView

    Of course. Thank you.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Different text styles in a single cell of QTableView?
    By xfurrier in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2009, 06:49
  3. How to center text in a QTableView
    By dougbroadwell in forum Qt Programming
    Replies: 9
    Last Post: 26th March 2009, 11:17
  4. Lists/multiline text in QTableView cells
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 23:43
  5. Text in QTableView cells not visible
    By juliarg in forum Newbie
    Replies: 2
    Last Post: 22nd March 2007, 15:49

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.