QT QGraphicsView update 实时刷新问题

路大腿 路大腿 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
大家好,遇到个问题,车标根据收到的经纬度信息更新位置,发现更新的频率大概是1s更新一次,实际设置的时间是200ms。
设置了下面两种方法,都无效果,求助
1.this->viewport()->repaint(0,0,320,180);
2.this->viewport()->update();

bool g_test = true;
graphicsView::graphicsView()
{
if(SHAPEMANAGE_SING->readlayer())
{
SHAPEMANAGE_SING->initData();
if(g_test)
{
SHAPEMANAGE_SING->testData();
}
}
m_pos = 0;
m_scare = 5;
m_ni = 0;
m_graphicsScene = new QGraphicsScene;
// m_graphicsScene->setBackgroundBrush(Qt::black);
setFrameStyle(QFrame::NoFrame);
m_graphicsScene->setSceneRect(0, 0, 320, 180);
// setBackgroundBrush(Qt::black);
setAlignment(Qt::AlignCenter);
setRenderHint(QPainter::Antialiasing, false);
setDragMode(QGraphicsView::ScrollHandDrag);
setOptimizationFlags(QGraphicsView::DontSavePainterState);
setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setWindowFlags(Qt::FramelessWindowHint);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);


setScene(m_graphicsScene);
populateScene();
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(handleOutTiemr()));
timer->start(200);
}

void graphicsView::handleOutTiemr()
{

m_graphicsScene->clear();
populateScene();

if(g_test)
{
if(m_pos >= 0 && m_pos < SHAPEMANAGE_SING->m_testPos.length())
{
dataPoint carPos;
carPos.latitude = SHAPEMANAGE_SING->Singleton()->m_testPos.value(m_pos).X;
carPos.longitude = SHAPEMANAGE_SING->Singleton()->m_testPos.value(m_pos).Y;
//qDebug("x %f, y %f",carPos.latitude,carPos.longitude);
SHAPE_DATAMANAGE->setCarPos(carPos);
m_pos ++;
}
else
{
m_pos = 0;
}
}
// 下面两种刷新都无效果
// this->viewport()->repaint(0,0,320,180);
// this->viewport()->update();
}

...全文
评论 3
收藏 已收藏
分享
返回顶部
路大腿
Qt 21,503 成员 26,693 内容