Results 1 to 6 of 6

Thread: How can I swipe one image to left or right on the same x and different y by mouse?

  1. #1
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question How can I swipe one image to left or right on the same x and different y by mouse?

    Actually my image can be moved but I want it to move on only an axis(x) that mean the image can not swipe to top or bottom but can be swiped to right or left only. Can everyone give me code or idea?

  2. #2
    Join Date
    Oct 2012
    Posts
    13
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How can I swipe one image to left or right on the same x and different y by mouse

    Define a constant for the Y cord. , for each mouse event entry , if y =! constant Y , Y = constant Y.

  3. #3
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How can I swipe one image to left or right on the same x and different y by mouse

    Can you give me example?

  4. #4
    Join Date
    Oct 2012
    Posts
    13
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How can I swipe one image to left or right on the same x and different y by mouse

    I'm not yet familiar with the drag/drop mouse events, only with the clicking, but with each mouse press/movement the event returns the (x,y) cord. of the cursor on the scene.

    So, the code might be something like this :

    qreal fixed_Y = the value you want for the Y at all times

    QPoint *toMove = new QPoint(0,fixed_Y);

    toMove->setX ( event->scenePos().x() ) ; //Event function will return an integer, this integer would be casted to qreal then stored in toMove
    toMove->setY( fixedY) ;

    yourItem ->setPos( *toMove) ;


    now for each time the mouse moves/getting pressed, it will retrive the click on the X axis only, while the Y (defined as a constant & never to change) is fixed at all times.

  5. The following user says thank you to AtlasS for this useful post:

    chong_kimkeang (8th October 2012)

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How can I swipe one image to left or right on the same x and different y by mouse

    Assuming you are using the QWidget::mousePressEvent(), mouseMoveEvent(), and mouseReleaseEvent() then:
    • When the mouse button is pressed capture the mouse position (QPoint or QPointF) into a member variable
    • During mouse moves while dragging take the current mouse position and insert the y (for horizontal drag) or x (for vertical) of the original click point. Use this hybrid point for any drawing/scene changes you trigger here.


    BTW: No need to allocate QPoint/QPointF objects on the heap like AtlasS has done. These are value objects and copied on use.

  7. The following user says thank you to ChrisW67 for this useful post:

    chong_kimkeang (8th October 2012)

  8. #6
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How can I swipe one image to left or right on the same x and different y by mouse

    Now I am using Scene for setFlag() to move the image but now I don't want to use it. Do you have other ways to do with this?

Similar Threads

  1. Mouse Right or Left click ???
    By anjanu in forum Qt Programming
    Replies: 9
    Last Post: 27th August 2011, 18:41
  2. Replies: 4
    Last Post: 29th August 2010, 18:16
  3. Replies: 8
    Last Post: 10th June 2010, 07:34
  4. Emulating Enter key with left mouse click
    By wconstan in forum Newbie
    Replies: 6
    Last Post: 30th December 2009, 16:16
  5. combining Alt + Left Mouse Button
    By speedracer in forum Qt Programming
    Replies: 1
    Last Post: 3rd June 2009, 13:29

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.