QTJambi: QAbstractItemModel.SetData is not called



  • 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.



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

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


Log in to reply
 

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