QTableWidget内容不刷新

解决方法

使用如下代码:
ui->tableWidget->viewport()->update();

原因

update()是更新这个控件
viewport()->update()是更新这个控件里面的内容

进一步分析

QTableWidget Class 官网的资料如下
http://doc.qt.io/qt-5/qtablewidget.html
顺着继承关系,一步步往上找,会发现如下说明

Note: If you inherit QAbstractItemView and intend to update the contents of the viewport, you should use viewport->update() instead of update() as all painting operations take place on the viewport.

链接:https://www.jianshu.com/p/1eecf053b742

posted @ 2020-03-03 22:26  friedCoder  阅读(1183)  评论(0)    收藏  举报