QT QGraphicsView update 实时刷新问题
路大腿 2018-11-12 04:25:23 大家好,遇到个问题,车标根据收到的经纬度信息更新位置,发现更新的频率大概是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();
}