Results 1 to 1 of 1

Thread: moving labels to exact location with mouse move event resulted in jumpy locations

  1. #1
    Join Date
    Dec 2010
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default moving labels to exact location with mouse move event resulted in jumpy locations

    Hi all,

    I've searched and read several documents and threads regarding exact positioning of a child widget. I tried to code it but still having a problem.

    Here's my code;

    Qt Code:
    1. void BoxExample::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. if(_mouseLeftPressed && this->objectName()=="Box_A"){ // Box_A type QLabel
    4.  
    5. this->move(mapToParent(event->pos()-_offset)); // Box_A moves as expected
    6.  
    7. _tmp=this->parentWidget()->findChild<QWidget *>("Box_B"); // Box_B type QLabel
    8. if(_tmp){
    9. _tmp->move(mapToParent( QPoint(0, event->pos().y()-_offset.y()) ) );// Box_B jumps around
    10. _tmp=NULL;
    11. }
    12.  
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    I can get Box_A to move exactly where I wanted it to be, but Box_B which is supposed to be sliding up and down the Y axis is jumping around in the parent widget. What's the right method for the child coordinate transformation?


    ------------------------------------------------------------------------

    I solved it by passing this->pos().y() position directly to Box_B.

    Qt Code:
    1. void BoxExample::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. if(_mouseLeftPressed && this->objectName()=="Box_A"){ // Box_A type QLabel
    4.  
    5. this->move(mapToParent(event->pos()-_offset)); // Box_A moves as expected
    6.  
    7. _tmp=this->parentWidget()->findChild<QWidget *>("Box_B"); // Box_B type QLabel
    8. if(_tmp){
    9. _tmp->move(QPoint(0, this->pos().y() ));// Box_B slides up and down Y axis
    10. _tmp=NULL;
    11. }
    12.  
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Still do not understand the whole mechanism behind child parent transform properly. It seems that all transformations are done relatively, right?


    Thanks.

    Cheers,
    Faizol
    Last edited by faizol; 9th October 2012 at 22:37.

Similar Threads

  1. Problem with QGraphicsScene mouse move event
    By Nesbit in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2012, 18:12
  2. Replies: 3
    Last Post: 7th January 2012, 08:38
  3. Replies: 4
    Last Post: 10th June 2010, 13:31
  4. mouse move event filtering in PyQt4
    By lucaf in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2009, 14:53
  5. Mouse Move Event
    By merry in forum Newbie
    Replies: 5
    Last Post: 3rd June 2007, 06:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.