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. ListView Delegate
Qt 6.11 is out! See what's new in the release blog

ListView Delegate

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.4k Views 3 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.
  • N Offline
    N Offline
    nitishjo
    wrote on last edited by
    #1

    I have ListView. In the Delegate I have painted fillrect at particular index once or twice as needed. I wanted help in how do I create widget i.e QLabel for every rect differently. Please advice.

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

      Hi,

      Something's not clear here, are you using widgets or Qt Quick ?

      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
      • N Offline
        N Offline
        nitishjo
        wrote on last edited by nitishjo
        #3

        Hi,
        I am using Widgets.I need to put three different widgets in single index in listview

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Hi,

          In general you have to reimplement createEditor() and setEditorData on the delegate to create a Widget.

          Could you show your code ?

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nitishjo
            wrote on last edited by
            #5

            for(int i = 0;i<m_numberOfSlots;i++)
            {
            int sheetCountPerSlot = index.data(Qt::UserRole).toInt();

                if(index.row()==i)
                {
                    painter->setPen(slotPen);
                    painter->drawRect(option.rect);
                    for (int var = 0; var < sheetCountPerSlot; var++)
                    {
            
                        const_cast<QRect&>(r)= QRect(x,y,width,height);
                                        painter->setRenderHint(QPainter::Antialiasing,true);
                                        painter->setPen(sheetPen);
                                        painter->fillRect(r,Qt::blue);
                        const_cast<QString&>(m_numberText) = QString::number(i)+"-"+QString::number(var);
                        painter->setPen(sheetNumberPen);
                        painter->drawText(r,m_numberText);
                        x= x+width +10;
                    }
            
                }
            }
            

            In the above code I am painting rect at same index many times which i want.
            So when in create editor I want render each rect to be Widget say (QLabel) so if there are 3 rects then when i click create editor is called so the clicked one should be QLabel. Please advice.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              Are you using the paint() method?

              In that case IMO is better to use createEditor()

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nitishjo
                wrote on last edited by
                #7

                Yes I am using paint method

                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