PDA

View Full Version : QListWidget: widget sometime can't alignment to baseline.



titanchen6886
23rd September 2016, 02:49
Hi all
I use a QListWidget to show a custom widgets that include a label and checkbox.
But sometimes, these custom widgets didn't alignment to a baseline, like blow picture
12119

And you can see there is a light-blue block above the widget that doesn't align.
here is the code i insert the custom widget to qlistwidget

CustomWidget*cgv = new CustomWidget();

cgv->setChecked(cellPassed[j].checked); // set checkbox state
cgv->setImage(QPixmap::fromImage(qimg)); // set the image show by QLabel

QString itemName = "block" + QString::number(i); // assign a name to the item to search it by name.
QListWidgetItem *item = new QListWidgetItem(itemName, ui->listWidget);

ui->listWidget->addItem(item);
item->setSizeHint(cgv->size());
ui->listWidget->setItemWidget(item, cgv); // insert the custom widget to the current item.

I try to set Qlistwidget's resize mode to batched and set batchsize to 1, it looks work for this issue,
but batchsize 1 is not good for display while resize the QListWidget content.

does anyone have any comment for this issue?
thanks a lot.

BR, Titan.Chen

derrickbj
27th September 2016, 16:52
What are you using in the UI to display the list widget?

titanchen6886
6th October 2016, 03:58
Hi
I use QT's designer form to create the ui.