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();
-
Hi,
Can you show your original code ?
-
-
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); }
-
Are you sure the size of the widgets are valid when you set them ?
-
What version of Qt are you using ?
On what platform ?
Can you provide a minimal compilable example that shows that behaviour ?