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?

    Regards.



  • 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":http://qt-project.org/doc/qt-4.8/QAbstractTableModel.html#subclassing

    Also you can change the EditTriggers using

    @ui->tableView->setEditTriggers(QAbstractItemView::yourRequiredEditTrigger);@



  • Thank you for your answers!

    I have the following code (Ruby syntax)

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

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

    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:
    @
    @ui.tableView.setEditTriggers(QAbstractItemView::AllEditTriggers)
    @

    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":http://paste.ideaslabs.com/show/npRYMkeMqC if you want to see it in detail.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.