[solved] Access model data in paint function



  • Hello
    I have a list view to which I've applied a @QStandardItemModel model( 10, 4 )@ model. I've also implemented a delegate, and my intention is to draw the item based on the cells in the "active row". My problem is how to access the data... The data() function of the model want a @QModelIndex@ but I can't use the one passed as a variable as it refers to the first column. Instead I've tried the following:

    @QModelIndex typeIndex = index.model()->createIndex(index.row(),1); // replacing 1->2,3 to access the following cells
    type = index.model()->data( typeIndex, Qt::DisplayRole ).toString();@

    but it fails as createIndex is protected... What is the correct way to get data from a model? Thanks!
    Richard



  • You should use the "index":http://doc.qt.nokia.com/4.7/qabstractitemmodel.html#index method of the model.



  • works, great, thank you!
    Richard

    @
    QModelIndex typeIndex = index.model()->index(index.row(),1);
    type = index.model()->data( typeIndex, Qt::DisplayRole).toString();
    @


Log in to reply
 

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