QTableWidget 中加入 图标居中问题的解决

发布时间:2023年12月25日

思路一:直接在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());

欢迎讨论。

文章来源:https://blog.csdn.net/Ricardo_XIAOHAO/article/details/135206159
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。