思路一:直接在QTabelWidget中加入 QTableWidgetItem ,设置 item 的 icon
问题:难以居中
思路二:在 QTableWidget 中 插入 QLabel ,把图标放到 QLabel 上
问题:存在点击图标困难的问题
思路三:直接插入 QPushButton ,设置 QPushButton 的Icon
QPixmap pixmap=copy_label->grab(copy_label->rect());//复制其他 QLabel 上的图标QPushButton *button_temp=new QPushButton();button_temp->setIcon(QIcon(pixmap)); //放到 button 上button_temp ->setStyleSheet("background-color: #171E2B;border: none;"); 设置颜色,隐去边框current_task_tableWidget->setCellWidget(current_task_tableWidget->rowCount()-1,3,button_temp);//加入 QButtonGroup 中方便管理operation_buttons->addButton(button_temp,operation_buttons->buttons().size());
欢迎讨论。