Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QListWidgetItem is not drawn correctly



  • I build up a ruse of CustomWidgets in a QListWidget. So far, it works well.
    A problem occurs when I move the vertical scroll bar downwards and want to display items that were not previously visible.
    Then they are inserted as transparent rectangles, I can click them and respond to the clicks, but they are not drawn. They stay transparent!

    I insert a picture to get a rough idea of the problem: https://ibb.co/Z6dd70X

    In my QListWidget I try to repaint it, but it doesn't work:

    QListWidget::verticalScrollbarValueChanged(value);
    auto item = this->itemAt(QPoint(24, value));
    if (!item)
    {
        return;
    }
    
    auto widget = this->itemWidget(item);
    if (!widget)
    {
        return;
    }
    
    //    widget->resize(widget->size());
    //    widget->repaint();
    widget->update();
    

  • Lifetime Qt Champion

    Hi,

    Can you show your original code ?



  • What do you want to see? Adding the items, or something else?
    Btw. you see the items, what is the relevance of the adding items code?
    The issue is, the items are not correctly painted, as described above.
    So which part of the code, can I show you?



  • This is the code where the items are added to the QListWidget:

    void ListControl::AddCustomWidget(QWidget* customWidget, const QSize& size, bool forceSize)
    {
        if (forceSize)
        {
            customWidget->adjustSize();
        }
    
        auto displaySize = customWidget->size();
        auto width = size.width();
        auto height = size.height();
    
        auto item = new QListWidgetItem(this);
        this->addItem(item);
    
        if (width >= 0)
        {
            displaySize.setWidth(width);
        }
        else
        {
            displaySize.setWidth(displaySize.width() - (this->verticalScrollBar()->width() + this->rightSpace));
        }
    
        if (height >= 0)
        {
            displaySize.setHeight(height);
        }
    
        item->setSizeHint(displaySize);
        this->setItemWidget(item, customWidget);
    }
    

  • Lifetime Qt Champion

    Are you sure the size of the widgets are valid when you set them ?



  • Yes, absolutely! I have checked it. Furthermore the items rectangles are drawn, just theirs content isn't


  • Lifetime Qt Champion

    What version of Qt are you using ?
    On what platform ?
    Can you provide a minimal compilable example that shows that behaviour ?


Log in to reply