Qt子控件调用update或repaint无效

当继承QAbstractItemView(如QHeaderView, QListView, QTableView)子类的时候,由于实现某个逻辑需要直接调用update或repaint时是不会触发paintEvent,因为Api文档里面说了:

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.

正确的做法是使用

viewport()->update();

你可能感兴趣的:(Qt)