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. Transformation of co-ordinates on the graphics scene
QtWS25 Last Chance

Transformation of co-ordinates on the graphics scene

Scheduled Pinned Locked Moved Solved General and Desktop
graphics scenegraphics viewgraphicsitemtransforms pain
4 Posts 2 Posters 768 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.
  • F Offline
    F Offline
    faiszalkhan
    wrote on 27 Dec 2018, 17:02 last edited by faiszalkhan
    #1

    I have QGraphicsView as central widget of QMainWindow
    I am binding scene and the view as follows,

    /* Constructor of mainWindow */
    scene = new Canvas(&strContextMenu, this);
    ui->graphicsView->setScene(scene);

    /* Setting the view as the central widget */
    setCentralWidget(ui->graphicsView);

    /* Setting alignment of view to the top left */
    ui->graphicsView->setAlignment(Qt::AlignLeft | Qt::AlignTop);

    Problem Statement:
    When I paint a graphics Item on the scene(Position is the click of the mice), only the first Item is drawn on the top left of the view. Subsequent graphic Items of the same type do not experience this and are drawn where intended(position of the click of the mice)

    Requirement is to draw the items wherever mice is clicked which is achieved by using scene->setSceneRect(QRectF(0, 0, 1000, 700)) which
    I don't want to do as I want the size of the scene to be hardcoded.

    I have tried using the following but it doesn't seem to work.
    ui->graphicsView->setTransformationAnchor(QGraphicsView::NoAnchor);
    ui->graphicsView->resetTransform();

    I believe it is some transform issue between the view and the scene but I am not getting it.

    Please help!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Dec 2018, 21:55 last edited by
      #2

      Hi,

      What version of Qt are you using ?
      On what OS ?
      Can you show the current code you are using ?

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        faiszalkhan
        wrote on 28 Dec 2018, 10:42 last edited by
        #3

        Hi, I am on Qt 5.9. Operating System MacOS Mojave. The code I shared above is the constructor of the mainWindow and where I see the problem.

        Is there any specific snippet you'd like to see ?

        Thanks.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Dec 2018, 21:50 last edited by
          #4

          What would be nice is to have a minimal compilable example that shows that behaviour.

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

          1 Reply Last reply
          0

          2/4

          27 Dec 2018, 21:55

          • Login

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