当前位置: 代码迷 >> QT开发 >> Qt图元的刷新解决办法
  详细解决方案

Qt图元的刷新解决办法

热度:177   发布时间:2016-04-25 03:04:25.0
Qt图元的刷新
我用qt做了一个传感器的拓扑图,在传感器节点掉线的时候将对应的图元填充为灰色,在传感器重新上线后将对应的图元填充为原来的颜色,现在的问题是,当传感器掉线的时候,图元不能自动填充为灰色,必须是用鼠标点击图元之后才能改变颜色,但是在传感器上线之后,图元却可以自动填充为原来的颜色,在画图的时候我用的是QGraphicsView QGraphicsScene,图元是继承自QGraphicsItem,在图元刷新的时候使用的是update()方法,这个问题让我很困扰,有哪位大神会的,帮帮忙啊
------解决思路----------------------
确认是否收到了掉线消息,另外确实update方法给定的区域、item是否正确。
------解决思路----------------------
void QGraphicsItem::update(const QRectF & rect = QRectF())
Schedules a redraw of the area covered by rect in this item. You can call this function whenever your item needs to be redrawn, such as if it changes appearance or size.

This function does not cause an immediate paint; instead it schedules a paint request that is processed by QGraphicsView after control reaches the event loop. The item will only be redrawn if it is visible in any associated view.

As a side effect of the item being repainted, other items that overlap the area rect may also be repainted.

If the item is invisible (i.e., isVisible() returns false), this function does nothing.

See also paint() and boundingRect().

现在的问题是,当传感器掉线的时候,图元不能自动填充为灰色
吊线的时候需要去调用item.update()刷新,item并不知道吊线,需要程序里通知item
  相关解决方案