Getting Image from MySQL into tableWidget in PyQt5

后端 未结 1 1939
轮回少年
轮回少年 2021-01-28 03:26

I have been able to get data from database and populate into the tableWidget, but the image column is not shown. I tried a code I found online and still, it didn\'t work. The im

1条回答
  •  醉话见心
    2021-01-28 03:37

    The logic to use the bytes (in my previous answer I proposed to use base64 so I use it in this case as well) to build a QPixmap that can be converted into a QIcon that can be displayed in the QTableWidget:

    for row_number, row_data in enumerate(rows):
        self.ui.tableWidget.insertRow(row_number)
        for column_number, column_data in enumerate(row_data):
            it = QTableWidgetItem()
            if column_number == 1:
                pixmap = QPixmap()
                pixmap.loadFromData(QByteArray.fromBase64(row_data))
                icon = QIcon(pixmap)
                it.setIcon(icon)
            else:
                it.setText(row_data)
            self.ui.tableWidget.setItem(row_number, column_number, it)
    

    0 讨论(0)
提交回复
热议问题