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. [solved] Access model data in paint function

[solved] Access model data in paint function

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k 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.
  • T Offline
    T Offline
    ThaRez
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

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

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ThaRez
        wrote on last edited by
        #3

        works, great, thank you!
        Richard

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

        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