Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAbstractItemModel and inserting rows and columns
Forum Updated to NodeBB v4.3 + New Features

QAbstractItemModel and inserting rows and columns

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewQtGuy
    wrote on last edited by NewQtGuy
    #1

    Hello,

    I have sort of a general question about inserting new rows into a model after it has already been loaded. I have an editable model derived from QAbstractItemModel and it is initially loaded with rows all having 4 columns. I then want to add a row with 4 columns to a parent that already has existing rows. Is there a way using the standard interface for QAbstractItemModel to do this? If I do an insertRow() with a following insertColumn() then won't the existing rows under the parent get columns inserted as well (resulting in too many columns for those rows) ?

    I've tried a "roll my own" solution that inserts a row between calls to beginInsertRow() and endInsertRow() and then inserts the columns for that row between the beginInsertColumns() and endInsertColums(). Unfortunately, My view behaves as if there is only a single column. I'm wondering if there is a problem doing this as it is sending signals implying that the columns have changed for all the rows under the parent but they have only changed for the one row.

    Any suggestions or insight appreciated.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Are you trying to build some sort of tree model ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alex_malyu
        wrote on last edited by alex_malyu
        #3

        Without looking in the source code I can't say for sure, but it is fairly possible that you can't call beginInsertColumns within beginInsertRow - endInsertRow block since they might use the same structure to keep data passed at beginInsertColumns and beginInsertColumns.
        especially counting that documentation states that end... functions have to be called immediately afterwards.

        If you do a lot of changes you might consider using beginResetModel endResetModel instead.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NewQtGuy
          wrote on last edited by
          #4

          Well, it seems I am able to get past the problem I was having. I think the thing that actually fixed my problem (the view not showing all the columns for a row inserted under a parent not having any rows) was not implementing the insertColumns() properly. The case where you can use the insertColumns() to create a row with N columns under a parent without rows. In this case I needed to have both the beginInsertRows() / endInsertRows() signaling and then the beginInsertColumns() / endInsertColumns() signaling.

          Thanks for bearing with me and your advice!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved