基本上我想要做的是爲列表中的每個數字繪製矩形。數字越大,矩形越大。 我的問題是,當我真的想要這樣做時,一步一步地在每張圖畫之間等待幾秒鐘。我已經尋找了一些解決方案,但我無法讓他們爲這個特殊情況工作。我看到我可以使用fflush釋放緩衝區中的任何內容,但我不知道如何使用它。在qt中使用paintevent的循環內睡眠C++
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
int weight=300/lista.size;
int posx=weight;
for (int i=1; i<=lista.size; i++){
List_node * node = list.get_element_at(i);
int num=node->getValue(); //this returns the value of the node
if (i==3){
painter.setBrush(QBrush(Qt::red, Qt::SolidPattern)); // this line is to draw a rectangle with a different color. Testing purposes.
}
painter.drawRect(posx,400-(num*10),weight,num*10);
sleep(1); //this sleep isn't working correctly.
painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
posx+=weight;
}
任何幫助將非常感激。
非常感謝!這解決了它。 –