QListWidget::setItemWidget The Selection area behind the label image
-
@joeQ The selection rect is already at foreground. There might be some other problem in your code.
Here a simple test I did:for(int i=0; i<10; i++) { QListWidgetItem *item = new QListWidgetItem; item->setText("Item"); item->setIcon(QIcon("image.png")); ui->listWidget->insertItem(row, item); } -
@joeQ The selection rect is already at foreground. There might be some other problem in your code.
Here a simple test I did:for(int i=0; i<10; i++) { QListWidgetItem *item = new QListWidgetItem; item->setText("Item"); item->setIcon(QIcon("image.png")); ui->listWidget->insertItem(row, item); } -
@joeQ Unfortunately I too am not aware of this kind of behaviour. I have reduced the problem to the following for anyone else to test:
listWidget->setViewMode(QListView::IconMode); listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); for(int i=0; i<10; i++) { QPushButton *label = new QPushButton; label->resize(50,50); label->setText("Button"+QString::number(i)); QListWidgetItem *item = new QListWidgetItem; item->setSizeHint(label->size()); listWidget->insertItem(i, item); listWidget->setItemWidget(item, label); }For eg. following works:
Use
QLabelinstead and set only thetext. But if we set pixmap for label then its the same behavior.
Is there any other setting ? Or only subclassing might solve this problem ? -
@joeQ Unfortunately I too am not aware of this kind of behaviour. I have reduced the problem to the following for anyone else to test:
listWidget->setViewMode(QListView::IconMode); listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); for(int i=0; i<10; i++) { QPushButton *label = new QPushButton; label->resize(50,50); label->setText("Button"+QString::number(i)); QListWidgetItem *item = new QListWidgetItem; item->setSizeHint(label->size()); listWidget->insertItem(i, item); listWidget->setItemWidget(item, label); }For eg. following works:
Use
QLabelinstead and set only thetext. But if we set pixmap for label then its the same behavior.
Is there any other setting ? Or only subclassing might solve this problem ? -
Hi,
It's because you are setting a widget on a cell, the widget is "above" the cell.
If you only want to show an image then you should use a custom QStyledItemDelegate.
-
Hi,
It's because you are setting a widget on a cell, the widget is "above" the cell.
If you only want to show an image then you should use a custom QStyledItemDelegate.
@SGaist Hi, Thank u. and if I don't want to use a custom QStyledItemDelegate. What should I do ?
My Widget has image label and text label, The important thing is that some of my structure data is stored in the Widget class members, eg: structure pointer.
I also used try
setItemDatafunction, but Data type mismatch. so, i subclass the QWidget. -
From the setItemWidget documentation: it's to display static content. It's not meant to handle D&D or editing.
Why do you need to embed custom data in that widget ?
-
From the setItemWidget documentation: it's to display static content. It's not meant to handle D&D or editing.
Why do you need to embed custom data in that widget ?