Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QTJambi: QAbstractItemModel.SetData is not called

QTJambi: QAbstractItemModel.SetData is not called

Scheduled Pinned Locked Moved Solved Language Bindings
2 Posts 1 Posters 1.3k Views
  • 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 Offline
    P Offline
    Palikur
    wrote on last edited by
    #1

    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
    0
    • P Offline
      P Offline
      Palikur
      wrote on last edited by
      #2

      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
      1

      • Login

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