Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved QTJambi: QAbstractItemModel.SetData is not called

    Language Bindings
    1
    2
    1079
    Loading More Posts
    • 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.
    • P
      Palikur last edited by

      Hi,

      I'm developing a very simple table view on QtJambi using a model/view implementation. My QTableView is configured as follows:

          partTabView = new QTableView(gridLayoutWidget);
          partTabView.setObjectName("partTabView");
          partTabView.setSortingEnabled(true);
          partTabView.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows);
          partTabView.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection);
          partTabView.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff);
          partTabView.setEditTriggers(EditTrigger.AllEditTriggers);
          
          
          partdata = new ParticipantModel(gd);
          partTabView.setModel(partdata);
          partTabView.itemDelegate().commitData.connect(this, "on_action_Edit_Part(QWidget)");
      
          partdata.dataChanged.connect(this, "on_data_changed(QModelIndex, QModelIndex)");
      

      And on the model size I have the following flags and setData definitions in my model:

      public final Qt.ItemFlags flags(QModelIndex index)
      {
      	Qt.ItemFlags flags = new Qt.ItemFlags(Qt.ItemFlag.ItemIsEnabled);
      	
          if (!isIndexValid(index)) {
          	return flags;
          }
          flags = super.flags(index);
          
          flags.set(Qt.ItemFlag.ItemIsSelectable);
          flags.set(Qt.ItemFlag.ItemIsEditable);
          
          return flags;
      }
      
      public final boolean setData(QModelIndex index, QObject value, int role)
      {
      	if (!isIndexValid(index))
      		return false;
      	
          // Check Role
      	if (role == Qt.ItemDataRole.EditRole)
      	{
          	List<String> l = m_gridData.get(index.row());
          	l.set(index.column(), value.toString());
          	m_gridData.set(index.row(), l);
          	dataChanged.emit(index, index);
      	}
      	return true;
      }
      

      I have neither any custom delegate nor editor, I'm using the default ones from QTableView. I manage to insert/remove and edit the cells but I cannot update their contents. The initial set values are always replacing the ones I type. Actually, the setData function is never called. As far as I understand, the default itemdelegate implements a "setModelData" function which automatically calls the setData function on the model so I don't need to call it myself. Am I missing something?

      Finally, upon edition of the cells (Return key pressed) my slot "on_action_Edit_Part(QWidget)" is properly called. I could call partdata.setData from there but I don't know how to retrieve the index and the typed data from the Editor.

      1 Reply Last reply Reply Quote 0
      • P
        Palikur last edited by

        Dummy me...the setData signature was wrong...it has to be:

        public final boolean setData(QModelIndex index, Object value, int role)

        1 Reply Last reply Reply Quote 1
        • P
          Palikur last edited by

          Dummy me...the setData signature was wrong...it has to be:

          public final boolean setData(QModelIndex index, Object value, int role)

          1 Reply Last reply Reply Quote 1
          • First post
            Last post