Results 1 to 5 of 5

Thread: Can't edit my QTableView cells

  1. #1
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Can't edit my QTableView cells

    Hi,

    1) I have setEditTriggers(QAbstractItemView::AllEditTriggers ) in the constructor of my derived QTableView class (which shouldn't be necessary), and

    2) I know that basic signals/slots are working since on_MyTable_activated(const QModelIndex& idx) works and idx does refer to the index of the cell I clicked on, and

    3) MyTable->model()->data(idx, Qt::EditRole) returns the actual contents of the cell.

    Yet no amount of clicking, keypresses, etc. will allow me to edit the cells, anyone know what's going on? NB model() is in this case a QSortFilterProxyModel, but that doesn't seem like it should make a difference...

    Matt

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't edit my QTableView cells

    Check if the item is actually editable: (MyTable->model()->flags(idx) & Qt::ItemIsEditable). If not, make it so.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

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

    MattPhillips (2nd February 2011)

  4. #3
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't edit my QTableView cells

    franz,

    Thank you! That was it. Specifically I needed to reimplement flags() as follows:


    Qt Code:
    1. Qt::ItemFlags MyTableModel::flags (const QModelIndex &index) const
    2. {
    3. return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
    4. }
    To copy to clipboard, switch view to plain text mode 

    I guess I hadn't expected this to be a property of the model, but rather the view, since you could conceivably want an item editable in one view but not editable in another. Anyway, thanks--

    Matt

  5. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't edit my QTableView cells

    Quote Originally Posted by MattPhillips View Post
    I guess I hadn't expected this to be a property of the model, but rather the view, since you could conceivably want an item editable in one view but not editable in another.
    Hmm, yes that could be the case. However, the model specifies whether an item is inherently editable. If you would want to block certain views from editing the item you could always use either a proxy model that strips the editable flag, or use a delegate that doesn't allow editing. In any case, the model/view framework has been designed in a way that changes through one view are (practically) immediately reflected in all other views. And well, if you run into such a situation, maybe it is time to reconsider your design (which is a good thing to do in any case)...
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  6. #5
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't edit my QTableView cells

    Thanks, I will keep those other options in mind.

    Matt

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. QTableView Edit Focus
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2010, 12:24
  3. Lists/multiline text in QTableView cells
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 23:43
  4. Text in QTableView cells not visible
    By juliarg in forum Newbie
    Replies: 2
    Last Post: 22nd March 2007, 15:49
  5. Editable cells in QTableView
    By TheRonin in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2006, 17:39

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.