PDA

View Full Version : Warning: Calling move() inside moveEvent() can lead to infinite recursion



babu198649
19th November 2007, 09:08
hi
i have a qlabel which has to be moved when the mouse receives the mouse move event.

but the documentation warns like this

Warning: Calling move() or setGeometry() inside moveEvent() can lead to infinite recursion.


Then how to achieve movement of a widget

jpn
19th November 2007, 09:11
You're interested of QWidget::mouseMoveEvent(), not QWidget::moveEvent(). See http://wiki.qtcentre.org/index.php?title=Moving_widgets for tips.

babu198649
19th November 2007, 13:14
thanks
but the t QWidget::mouseMoveEvent does not perform as expected.

here is the code, i dont know what is the bug in it


void IV_label::mouseMoveEvent ( QMouseEvent * event )
{
//the distance moved by mouse is mapped to top left of widget
this->move(mapToGlobal(event->pos()) - this->mapToGlobal(this->pos()));
}

the widget(label) moves and becomes invisble

i want to move a label using mouse

jpn
19th November 2007, 13:25
Well actually, it's you who moves the label widget to a non-sense location. Would you mind taking a look at the wiki article I gave link to?

babu198649
19th November 2007, 15:04
i read the article and it works because it takes the reference coordinate of its parents(
else
move(mapToParent(event->pos() - offset));
)

but i have a qscrollarea as my labels parent so i am going for global referencing.

cant we use move function for positioning the child widgets using global reference system.

babu198649
20th November 2007, 12:19
oh thanks it works actually there was a mix between the global and parent coordinates.