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. How to let QCursor appear at a certain position? (Only visually not functionally)
Forum Updated to NodeBB v4.3 + New Features

How to let QCursor appear at a certain position? (Only visually not functionally)

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 446 Views 3 Watching
  • 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.
  • S Offline
    S Offline
    StudentScripter
    wrote on last edited by StudentScripter
    #1

    I have an object that i resize via drag and drop, but when its rotated the cursor is gets of the original point the drag started on. The resizing is working fine on itself only the cursor is off. Attached a gif below. In the last frames you see that the mouse is of the corner.
    What can i do to get the cursor always aligned with the dragged corner?

    Rect rotate gif.gif

    Pl45m4P 1 Reply Last reply
    0
    • S StudentScripter

      I have an object that i resize via drag and drop, but when its rotated the cursor is gets of the original point the drag started on. The resizing is working fine on itself only the cursor is off. Attached a gif below. In the last frames you see that the mouse is of the corner.
      What can i do to get the cursor always aligned with the dragged corner?

      Rect rotate gif.gif

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @StudentScripter

      The real question and what you should try to figure out, is:
      Why is your item not where your cursor is?!

      The cursor (as mouse input) should define where your item goes, and not the other way round, so that you do some transformations which are a bit off and then quickly put your mouse there to "hide the error" ;-))

      It's like

      2 + 2 = 5           X ( wrong, but I take it)
      2 + 2 + 3 = 8       O ( correct, because 2 + 2 = 5 was accepted )
      

      Edit:

      Here's a hint what could have gone wrong:

      sceneFrame-0.jpeg

      As you can see from my edits (the lines), the cursor is aligned with the bottom right corner of the non-transformed rect...
      Can't tell what is wrong exactly, but you might want to start there :)

      Edit_2:

      I can imagine this may be the result of moving a non-transformed rect and then transforming it at its new position, which causes the visible item to rotate clockwise while the mouse stays at its original position.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      S 1 Reply Last reply
      3
      • Pl45m4P Pl45m4

        @StudentScripter

        The real question and what you should try to figure out, is:
        Why is your item not where your cursor is?!

        The cursor (as mouse input) should define where your item goes, and not the other way round, so that you do some transformations which are a bit off and then quickly put your mouse there to "hide the error" ;-))

        It's like

        2 + 2 = 5           X ( wrong, but I take it)
        2 + 2 + 3 = 8       O ( correct, because 2 + 2 = 5 was accepted )
        

        Edit:

        Here's a hint what could have gone wrong:

        sceneFrame-0.jpeg

        As you can see from my edits (the lines), the cursor is aligned with the bottom right corner of the non-transformed rect...
        Can't tell what is wrong exactly, but you might want to start there :)

        Edit_2:

        I can imagine this may be the result of moving a non-transformed rect and then transforming it at its new position, which causes the visible item to rotate clockwise while the mouse stays at its original position.

        S Offline
        S Offline
        StudentScripter
        wrote on last edited by StudentScripter
        #3
        This post is deleted!
        Pl45m4P 1 Reply Last reply
        0
        • S StudentScripter

          This post is deleted!

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @StudentScripter said in How to let QCursor appear at a certain position? (Only visually not functionally):

          CustomGraphicsScene::CustomGraphicsScene(QObject *parent)
          : QGraphicsScene(parent),  angleDegrees(0), scaleX(1.0), scaleY(1.0)
          {
          // Erstelle das Rechteck
          rectItem = new QGraphicsRectItem();
          rectItem->setRect(0, 0, 100, 100); // Rechteck von 100x100
          rectItem->setBrush(Qt::blue);
          rectItem->setPen(Qt::NoPen);
          rectItem->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges | QGraphicsItem::ItemSendsScenePositionChanges); // Rechteck bewegbar machen
          addItem(rectItem);
          

          I expected a custom QGraphicsItem with handles and not that it's handled by the scene.
          But makes sense if you want all items that are added to the scene to have the handles.

          may you can help me to spot whats wrong with it?

          After my hints you should be able to figure it out, as for non-involved persons it might be confusing to dive into your "logic".

          One more thought:
          The position where the mouse movement stops after dragging or resizing needs to be the corner (and handle position) of the transformed rect.
          Like I wrote before, I suspect your logic to be the other way round... if you resize/move the item along the cursor movement and stop with the cursor, but then transform it (by calling updateTransform()) afterwards, the item edges and corners will not be aligned with your cursor anymore.
          Therefore you need to include the current transformation in your calculations.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          S 1 Reply Last reply
          2
          • Pl45m4P Pl45m4

            @StudentScripter said in How to let QCursor appear at a certain position? (Only visually not functionally):

            CustomGraphicsScene::CustomGraphicsScene(QObject *parent)
            : QGraphicsScene(parent),  angleDegrees(0), scaleX(1.0), scaleY(1.0)
            {
            // Erstelle das Rechteck
            rectItem = new QGraphicsRectItem();
            rectItem->setRect(0, 0, 100, 100); // Rechteck von 100x100
            rectItem->setBrush(Qt::blue);
            rectItem->setPen(Qt::NoPen);
            rectItem->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges | QGraphicsItem::ItemSendsScenePositionChanges); // Rechteck bewegbar machen
            addItem(rectItem);
            

            I expected a custom QGraphicsItem with handles and not that it's handled by the scene.
            But makes sense if you want all items that are added to the scene to have the handles.

            may you can help me to spot whats wrong with it?

            After my hints you should be able to figure it out, as for non-involved persons it might be confusing to dive into your "logic".

            One more thought:
            The position where the mouse movement stops after dragging or resizing needs to be the corner (and handle position) of the transformed rect.
            Like I wrote before, I suspect your logic to be the other way round... if you resize/move the item along the cursor movement and stop with the cursor, but then transform it (by calling updateTransform()) afterwards, the item edges and corners will not be aligned with your cursor anymore.
            Therefore you need to include the current transformation in your calculations.

            S Offline
            S Offline
            StudentScripter
            wrote on last edited by StudentScripter
            #5

            @Pl45m4 Thanks alot, these are some good insights, i've done a mockup on how it is supposed to behave. Now gonna try to implement it properly. :) 67904bf7-e4bc-4739-89de-0217044219dd-image.png
            I'll report back if i stumble upon further problems, if you don't mind.

            1 Reply Last reply
            0

            • Login

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