Efficiently updating a QTableView at high speed

后端 未结 3 1158
萌比男神i
萌比男神i 2021-02-06 07:05

I\'m using a QTableView with a subclass of QItemDelegate to control the look and feel of the tableview\'s cells.

Each cell displays the name and status of a of an extern

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 07:38

    Cache the background image (cell background image, status and name) to the model as a QPixmap. Redraw that pixmap only when the status or the name are changed. In the common case you will only need to draw the cached QPixmap and the sensor value on top of that.

    Edit:

    Add fullRepaintNeeded flag to your data class. When status or name is changed, fullRepaintNeeded is set to true.

    When the delegate is painting the item, the delegate first checks the item's fullRepaintNeeded flag. If fullRepaintNeeded is true, then a new QPixmap is created and everything is painted to that QPixmap which is finally painted to the tableview. The QPixmap is then cached to the model (which means to your data class) with model's setData-function (but dataChanged is not called). fullRepaintNeeded is now set to false.

    But if fullRepaintNeeded is false in the delegate's paint function, a previously cached QPixmap is asked from the model, drawn to the tableview and the finally sensor value is drawn on top of that.

提交回复
热议问题