Qt 5.7 -> 5.8 add QIcon to QListwidget

890 views Asked by At

I want to upgrade my project from Qt 5.7 to Qt5.8. I have a function which shows an image on a QListWidget.

My project, a viewer makes a thumbnail from image and convert it to a QIcon. After creating the QIcon it is added to the QListWidget by inserting a new QListwidgetItem.

In 5.7 that worked well, but in 5.8 thumbnails are not shown.

Belows are codes

QIcon to QListWidget:

QIcon tmpIcon(pathOfImage);

ui.listWidget->addItem(new QListWidgetItem(tmpIcon, pathOfImage));

What makes this happen? How can I adjust to 5.8?


  • In 5.7 it works:

    In 5.7 it works!

  • In 5.8 it doesnt:

    In 5.8 ....


But right now, I found that small size of PNG can be shown in 5.8.

I don't know what is the problem. Maybe the size or the format of the image?

In 5.7 that didn't affect the QListwidget!

1

There are 1 answers

0
HyunWoo Park On

I did a experiment.

    QListWidgetItem* newItem = new QListWidgetItem();
    newItem->setIcon(tmpIcon);
    newItem->setText(pathOfImage);

after this, I tried to get newItem(QListWIdgetItem)'s icon and saved it to png.

   QIcon te2 = newItem->icon();
   QPixmap test = te2.pixmap(te2.actualSize(QSize(1024, 1024)));
   QFile file1(te + "yourFile.png");
   file1.open(QIODevice::WriteOnly);
   test.save(&file1, "PNG");

Regular JPG files couldn't be saved but only small logo png file could be saved properly. I think that set process between QIcon and QListWitgetItem is the main problem.