Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsView - move item by non linear value...
QtWS25 Last Chance

QGraphicsView - move item by non linear value...

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicsviewmove
3 Posts 2 Posters 466 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dariusz
    wrote on 10 Oct 2019, 17:56 last edited by
    #1

    Hey

    Right now the item is being moved to the mouse position.

    I would like a way to multiply the amount of mouse movement... say if I have a multiplier of 0.5, then move of 100 pixels in mouse distance would result in item moving by 50 pixels...

    Does qt offer any way of doing this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Oct 2019, 18:11 last edited by
      #2

      Hi,

      AFAIK, not directly (but I may be wrong though)

      Can you explain your use case ? It sounds strange to me that if I move an object with my mouse that it only moves half-way.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply 10 Oct 2019, 18:19
      0
      • S SGaist
        10 Oct 2019, 18:11

        Hi,

        AFAIK, not directly (but I may be wrong though)

        Can you explain your use case ? It sounds strange to me that if I move an object with my mouse that it only moves half-way.

        D Offline
        D Offline
        Dariusz
        wrote on 10 Oct 2019, 18:19 last edited by Dariusz 10 Oct 2019, 18:41
        #3

        @SGaist Its about precision moves, if user wants to move by tiny bit, scaling mouse movement by x value would allow that to happen. Else he would have to type 0.0001 0.0002 0.0003 etc etc.

        I think I could handle it using itemChange() and record initial mouse click press/release and calculate delta using that..

        Yep that seem to do the trick... I can now move my items by tiny amount and doing "Long precise drags"

                    deltaX = (newPos.x() - self.mMousePressPosition.x()) / 2
                    newPos.setX(newPos.x() - deltaX)
                    deltaY = (newPos.y() - self.mMousePressPosition.y()) / 2
                    newPos.setY(newPos.y() - deltaY)
        

        Small edit, function above works for "simple" items, but as soon as I get to child items with parent it appear to break... sigh. Needs some more math there

        1 Reply Last reply
        0

        1/3

        10 Oct 2019, 17:56

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved