Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QAbstractItemModel insert Row Error.



  • Regenerated rowCount function in QAbstractItemModel. At first, Row Count is 0 in QMap.

    When you add QPushButton and click this button, InsertRow becomes one line.
    However, you can not select or modify these added lines.

    What should I do? Thank you.


  • Lifetime Qt Champion

    @Pada_ said in QAbstractItemModel insert Row Error.:

    What should I do?

    Explain better and show the relevant code.
    Where can't you select/modify the lines? How are you adding them?



  • @jsulm

    In rowCount (), only the number of returns is selected. If you press the button to insertRow, the line is added on the screen but you can not select or edit it.

    If the return value of rowCount is 2, you can select and modify up to 2 lines on the screen first, and nothing will work from the 3rd line added by pressing the button.


  • Lifetime Qt Champion

    Hi,

    How did you re-implement row count ?
    How are you implementing the rows related functions ?



  • @Pada_
    Have you checked if you have all Qt::Itemflags set:

    Qt::ItemFlags YourCustomizedModelName::flags(const QModelIndex &index) const
    {
       if (index.isValid())
       {
           switch (index.column())
           {
           case 0:
           {
               return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled  | Qt::ItemIsSelectable | Qt::ItemIsEditable;
           }
           case 1:
           {
               return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled  | Qt::ItemIsSelectable | Qt::ItemIsEditable;
           }
           case 2: // end so on...
    

Log in to reply