Important: Please read the Qt Code of Conduct -

Editing a TableModel

  • Hello all,

    I have a MyClassTableModel that inherit from QAbstractTableModel then I set the model to a TableView. I want to edit the cells so I only have reimplemented flag() and setData() but does not work.
    It needed something else?


  • what's your edit trigger configuration? Usually, items react to double-click, but you can configure the triggers to react to single click, focus change. etc.

    also: if you try to edit an item, check the application output in your IDE. If editing fails due to missing flags or such, there should be a message saying "editing failed".

  • You can look in "Subclassing QAbstractTableModel":

    Also you can change the EditTriggers using


  • Thank you for your answers!

    I have the following code (Ruby syntax)

    class ObjectTableModel < Qt::AbstractTableModel
    def flag(index)
    return Qt::ItemIsEditable
    def setData(index, value, role = Qt::EditRole)
    #long code
    return true

    And then in a widget:
    class GUICustomerWidget < Qt::Widget
    def initialize()
    @ui.tableView.setEditTriggers(Qt::AbstractItemView::DoubleClicked )

    when I click on a row there is no an output error.
    I have for many days trying and reading forums and pages.

  • your edit trigger says 'double click'. Have you tried double-clicking an item? Simply clicking it won't trigger the edit mode.

    you could try this:

    This should allow you to enter edit mode with a single click.

  • rschaub I tried add this line too but nothing...
    I pasted my code (simplified) "here": if you want to see it in detail.

Log in to reply