1. Problem Qtablewidget cannot directly center the picture in item
Qt's Qtablewidget control can be used to display text and pictures
It itself provides a void Qtablewidget::setitem (int row, int column, Qtablewidgetitem *item) method for displaying pictures
Cases:
Ui->tablewidget->setitem (0,1,new Qtablewidgetitem (Qicon (": img/warn.jpg"), ""));
However, Qtablewidget only provides a way to center the text void qlistwidgetitem::settextalignment (int alignment)
Such as:
Ui->tablewidget->item (0, 0)->settextalignment (qt::alignhcenter);
This method only makes the text centered but not the center of the picture
See figure
Leng on the right cannot be centered
2. Use the Qlabel control to center the shape in the Qtablewidget
The void qtablewidget::setcellwidget (int row, int column, Qwidget *widget) method provided by Qtablewidget is used here
The specific code is as follows:
Qlabel *label = new Qlabel ();
Label->setpixmap (Qpixmap (": Img/warn.png"));
Label->setalignment (Qt::alignhcenter);
Ui->tablewidget->setcellwidget (0,1,label);
Effect as shown
Successfully implemented the item in Qtablewidget Center display picture