Results 1 to 4 of 4

Thread: Making a QTableWidget Editable

  1. #1
    Join Date
    Nov 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Making a QTableWidget Editable

    Hello,

    I am working with a QTableWidget the user will enter data into, but I cannot get the cells to become editable. Right now I'm doing the following:
    Qt Code:
    1. void MyClass::initTable(){
    2. // Add Cell 1
    3. item->setFlags(item->flags() & ~Qt::ItemIsEditable);
    4. item->setData(Qt::DisplayRole, "(0,0)");
    5. tableWidget->setItem(0,0,item);
    6. // Add Cell 2
    7. item = new QTableWidgetItem;
    8. item->setFlags(item->flags() & ~Qt::ItemIsEditable);
    9. item->setData(Qt::DisplayRole, "(1,0)");
    10. tableWidget->setItem(1,0,item);
    11.  
    12. tableWidget->setEditTriggers(QAbstractItemView::AllEditTriggers);
    13. }
    To copy to clipboard, switch view to plain text mode 

    This is just an example, but it shows what I'm trying to do. I also have an Editor that's being applied to QColor objects that are inserted into the table. I don't know if that would change how it functions, but I figured it wouldn't hurt to mention. It's the Editor that's straight out of the Qt Tutorials.

    Also, every other time I've tried to enter data into a table, it has worked. but not for this project. I don't know if it's the current version of Qt or what...

    Thanks =)

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Making a QTableWidget Editable

    Why do you set the items to not editable when you want them to be editable?

  3. #3
    Join Date
    Feb 2010
    Posts
    52
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default Re: Making a QTableWidget Editable

    Try using
    Qt Code:
    1. item->setFlags(item->flags() | Qt::ItemIsEditable);
    To copy to clipboard, switch view to plain text mode 

    Chris.

  4. #4
    Join Date
    Nov 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Making a QTableWidget Editable

    Hello again. I know it doesn't make sense to use ~Qt::ItemIsEditable, but it has worked in every other case. I tried I tried replacing the AND with an OR and removing the ~, but it still doesn't work. I tried installing an event filter on the object, but it doesn't seem to recognize my mouse clicks. I gets other events, but not QEvent::MouseButtonPress....

    EDIT:
    I figured it out. It was the ItemEditor that was eating the events.
    I had the following code:
    Qt Code:
    1. // EDITOR CALLS
    2.  
    3. QItemEditorCreatorBase *colorListCreator =
    4. new QStandardItemEditorCreator<ColorListEditor>();
    5.  
    6. factory->registerEditor(QVariant::Color, colorListCreator);
    7.  
    8. QItemEditorFactory::setDefaultFactory(factory);
    To copy to clipboard, switch view to plain text mode 
    And by doing that, it seemed to have been consuming the events. I have decided to remove the editor, and write a custom delegate to display the combo boxes in only specific columns.

    Thanks for all your input =)
    Last edited by llemes4011; 21st October 2010 at 19:29.

Similar Threads

  1. QTableWidget, one column editable
    By stella1016 in forum Qt Programming
    Replies: 5
    Last Post: 11th July 2012, 09:35
  2. trouble making simple DOM model example editable
    By Mamra in forum Qt Programming
    Replies: 6
    Last Post: 1st October 2009, 14:40
  3. QGraphicsTextItem is not editable
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 29th September 2009, 15:51
  4. how to set up a QHeaderView editable?
    By iguanna in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2008, 14:37
  5. QTreeWidget - Making a Column editable.
    By Preeteesh in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2007, 12:02

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.