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. How to paint the Person data on list and table view with delegate paint method
Forum Updated to NodeBB v4.3 + New Features

How to paint the Person data on list and table view with delegate paint method

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.3k Views 1 Watching
  • 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
    tokafr
    wrote on last edited by
    #1

    Hello guys!

    I have a trouble, I have Person data, model and delegate classes, Now I want to put all the information( including image icon of person) into the view cell, I must do it with paint() in delegate,
    so when I set the delegate to the view the cells should be filled with person data(including image it's important). How can I do it, can you give me some piece of code, here is what I started

    @ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {

    if(index.isValid())
    {
    
    
      Person person = index.model()->data(index,Qt::DisplayRole).value<Person>();
    
    
      if(option.state & QStyle::State_Selected)
      {
        painter->fillRect(option.rect,option.palette.highlight());
      }
      painter->drawPixmap(0,0,QPixmap(person.getIcon()));
    
      painter->drawText(option.rect,person.getName(),QTextOption());
    
    }
    

    }
    @

    it is very important for me and very thank you if you can help me

    [edit: corrected typo in guys SGaist]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What are you currently getting ? What are you expecting ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Now it paints only the icon and and overwrites the text
        I expect it to be Icon + the text and the size of icon must change when the cell size changes

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You will need different rectangles for each piece of information you want to display if you want to avoid overlapping. Currently, you are using the same rect for all pieces of content.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tokafr
            wrote on last edited by
            #5

            and how can I customize to be in the next of each other and not together

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              There is different ways to do that. The QPainter::drawImage functions can do scaling for you, or you can use QImage::scaled (or QImage::scaledToHeight or scaledToWidth) to first scale and then paint.

              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