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. QListview items are clipped on the left side
Qt 6.11 is out! See what's new in the release blog

QListview items are clipped on the left side

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.1k 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.
  • PemdasP Offline
    PemdasP Offline
    Pemdas
    wrote on last edited by Pemdas
    #1

    I am trying to draw qwidgets in a listview with a delegate. I can get the widget to render but it seems like there is clip window that is moving over the widget in the left direction as I draw them and I can't figure why. It's almost like the listview is adding a margin that grows with each item that is added, but somehow I am still drawing the widget at the right location.

    Kind of like this.

    <clip> --------------------
    <clip-clip> ---------------------
     void CustomItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
              const QModelIndex &index) const
    {
        MyWidget w("test", "test");
    
        //At some point I want to load the widget with data from here 
        if(index.data().canConvert<CustomModelItem>())
        {
            w.resize(option.rect.size()); 
            painter.save();
            //some kind of bug with passing topLeft in. I found this solution somewhere
            w.render(painter, painter->deviceTransform().map(option.rect.topLeft()));
            painter.restore();   
        }
        else
        {
            QStyledItemDelegate::paint(painter, option, index);
        }
    }
    

    Can anyone explain this behavior?

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

      Hi,

      Do you have that effect with the current code ? I must say I don't see the need of calling deviceTransform.

      Did you take a look at the Star Delegate example ? It might help you get started with custom painting.

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

        Star delegate manually draws a star. That is not what I want. I want to draw a widget specifically to pick up the style properties from a stylesheet. I can draw lines anywhere I want all day. It's the rendering of a widget that I am struggling with. I did a little more investigation and what I found is that the system clip QRegion in the QPainter is moving +3px to the right on every iteration in the loop of QListview's paint method. That completely explains the behavior that I am seeing, but I can't figure out why it is happening. I have been trying to see how QListWidget accomplished its drawing. It is definitely not calling render on the items in the list. It appears as though it is calling drawControl(...). I can't say for certain but I think QListWidget is simply drawing sections of itself. Each section is defined by the rectangle that represents one list item.

        I see one call to render for the what I assume is the viewport.

        Then I see a QStyle::drawControl() for every item in the list. However, the option.widget is always the viewport The only thing different is the target offset and the clip region. This is what makes me think it simply drawing the same widget in "chunks". I tried drawing my widget with QStyle::drawControl(), but I can't get it to render.

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

          Can you share a minimal code sample that reproduces this ?

          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

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved