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. Coordinates for QGraphicsView
Forum Updated to NodeBB v4.3 + New Features

Coordinates for QGraphicsView

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 868 Views 1 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.
  • L Offline
    L Offline
    leinad
    wrote on last edited by
    #1

    I placed a QGraphicsView inside a tab widget using QTCreator. In QtCreator the dimensions of the graphicsView is 6, 6, 687, 319.
    When I try to get the coordinates and size of the view via these commands:

    int sceneStartCornerX = ui->testGridGraphicsView->x(); //X coordinate of the left to corner of the QGraphicsView (6)
    int sceneStartCornerY = ui->testGridGraphicsView->y(); //Y coordinate of the left to corner of the QGraphicsView (6)
    int sceneEndCornerX = ui->testGridGraphicsView->width(); //Width of the QGraphicsScene (687)
    int sceneEndCornerY = ui->testGridGraphicsView->height(); //height of the QGraphicsScene (319)

    the returned results are 0, 0, 100, 30

    When I try to map the scene to the view and place rectItems, the items are skewed within the scene. Is there something else I need to do to make sure the ui->testGridGraphicsView values match the coordinates in QTCreator?

    I know I must be missing something. The view is inside a frame if that makes a difference.

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      When are you requesting these values ?

      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
      • L Offline
        L Offline
        leinad
        wrote on last edited by
        #3

        In the constructor

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Until the widgets are shown they have no "physical" dimensions.

          Also note that the size of the scene and the view do not necessarily match unless you made it so.

          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
          1
          • L Offline
            L Offline
            leinad
            wrote on last edited by
            #5

            This is what I did when I created the scene.
            //create the scene
            scene_ = new QGraphicsScene(sceneStartCornerX_,
            sceneStartCornerY_,
            sceneEndCornerX,
            sceneEndCornerY,
            ui->testGridGraphicsView);

            ui->testGridGraphicsView->setScene(scene_); //attach the scene to the view (QGraphicsView)

            //smooth graphics
            ui->testGridGraphicsView->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::TextAntialiasing);
            
            1 Reply Last reply
            0
            • L Offline
              L Offline
              leinad
              wrote on last edited by
              #6

              What do you mean until the widgets are shown? I assume the user must click on the tab. Is there a way to force it to see the dimensions without clicking on the tab?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Why not just build a "size less" scene ?

                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
                • L Offline
                  L Offline
                  leinad
                  wrote on last edited by
                  #8

                  You mean don't set the dimensions when setting up the scene?
                  scene = new QGraphicsScene(ui->testGridGraphicsView);

                  I did that with the same results.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    How are you placing the items on your scene ?

                    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
                    • L Offline
                      L Offline
                      leinad
                      wrote on last edited by
                      #10

                      Programmatically using dimensions. It looks fine but skewed because the original sizes are incorrect.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Please provide a minimal compilable example that reproduces that issue.

                        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
                        1
                        • L Offline
                          L Offline
                          leinad
                          wrote on last edited by
                          #12

                          Thanks, you actually helped me resolve the issue. I created a signal/slot when the tab is selected which now shows the view. At that point I get the coordinates and they show properly.

                          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