【发布时间】:2015-03-19 08:21:31
【问题描述】:
我是 QT 的新手,我的问题是循环刷新页面以在 QWidget 上移动。
详细地说,我有太多的点(这是一个椭圆跟随的路径,它们将被绘制为直线),我有一个椭圆将根据给定的两个点在屏幕上移动。在其移动过程中,路径发生了变化。因此将根据新路径再次绘制线条,椭圆应遵循新路径。我做了如下:
void MainWindow::paint(...){
painter.drawEllipse(circle) //circle is QRectF
//Also I need to draw lines according to pathPlanned
}
bool MainWindow::replan(){
//it calculates the planned path and if the ellipse does not reached the destination it can change the planned path here
}
void MainWindow::execute(){
while(replan()){
for (it = plannedPath->begin(); it != plannedPath->end(); it++){
//Lines should be redraw according to new pathPlanned
}
circle(...) // new position of ellipse is changed here
// I tried to put QThread::msleep(10) but I learned that it blocks GUI and then deleted it.
}
}
我的问题是循环运行得如此之快(像往常一样)并且在完成所有操作之前它无法刷新页面。然后立即在目的地上绘制椭圆。我看不到椭圆的移动。 我该如何解决?
【问题讨论】: