Using QtimerEvent in QGraphicsScene
The timerEvent, which is a member of a QGLWidget class shall be triggered when the mousemove-function is called. I thought I could do it like this:
void GLWidget::timerEvent(QTimerEvent *e)
{
if (e->timerId()==1 && refresh==true)
{
refresh = !refresh;
swapBuffers();
update();
}
}
It looks like this:
void OpenGLScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
int mousex = event->scenePos().x();
int mousey = event->scenePos().y();
if ((test->modus==2) && (test->move1 != -1))
{
p_list[test->move1].x=mousex-(1220);
p_list[test->move1].y=mousey-( 610);
test->refresh = !(test->refresh);
test->timerEvent(???);
update();
}
}
But somehow I dont know what to put into where the questions marks are. I have tried several things. It is开发者_StackOverflow中文版 not working. I want to set timerId()=1. Thanks for your help...
why don't you call your own event like :
void OpenGLScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
// ...
if ((test->modus==2) && (test->move1 != -1))
{
// ...
test->refresh = !(test->refresh);
//test->timerEvent(???); replaced by :
test->manuelUpdate(); // your own function
//...
}
}
and in your GLWidget :
void GLWidget::manuelUpdate()
{
if (refresh==true)
{
refresh = !refresh;
swapBuffers();
update();
}
}
精彩评论