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. QGraphicsItem positioning
Forum Updated to NodeBB v4.3 + New Features

QGraphicsItem positioning

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.3k Views 2 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.
  • canellasC Offline
    canellasC Offline
    canellas
    wrote on last edited by
    #1

    Hi,

    I have a QGraphicsEllipseItem object, which is randomly positioned, and I would like it not to go beyond the QGraphicsView borders, which are the same of the Window.

    I think I should make the QGraphicsScene exactly the same size of the QGraphicsView, but so far I failed to do that, and I am not sure that this is the correct way to do it.

    Does anyone have a suggestion how to do it? I would appreciatte any reference too.

    Thanks

    FlotisableF 1 Reply Last reply
    0
    • canellasC canellas

      Hi,

      I have a QGraphicsEllipseItem object, which is randomly positioned, and I would like it not to go beyond the QGraphicsView borders, which are the same of the Window.

      I think I should make the QGraphicsScene exactly the same size of the QGraphicsView, but so far I failed to do that, and I am not sure that this is the correct way to do it.

      Does anyone have a suggestion how to do it? I would appreciatte any reference too.

      Thanks

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      @canellas
      how about passing the QGraphicsScene::sceneRect() to QGraphicsView::fitInView() ?

      1 Reply Last reply
      0
      • canellasC Offline
        canellasC Offline
        canellas
        wrote on last edited by
        #3

        Thanks for your time!

        I tried to combine the two methods, but I failed to. Would you have an example?

        Thanks

        m.sueM 1 Reply Last reply
        0
        • canellasC canellas

          Thanks for your time!

          I tried to combine the two methods, but I failed to. Would you have an example?

          Thanks

          m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #4

          Hi @canellas

          The "extension" of the graphics scene is the combined extension of all its objects (ellipses). In the graphics view you can set the area (rect) of the graphics scene that you want it to show with: setSceneRect(rect);

          So you will have to define a rectangle in which to vary the ellipses and set the view to show this rectangle; and make the widget big enough to show the complete view, otherwise you will get scrollbars.

          -Michael.

          1 Reply Last reply
          0
          • canellasC Offline
            canellasC Offline
            canellas
            wrote on last edited by
            #5

            Thanks for your time.

            That's pretty much what I am doing.

            I set the QGraphicsView to show no scroll bars, and the QGraphicsScene width and height to 95% of the QGraphicsView's size.

            FlotisableF 1 Reply Last reply
            0
            • canellasC canellas

              Thanks for your time.

              That's pretty much what I am doing.

              I set the QGraphicsView to show no scroll bars, and the QGraphicsScene width and height to 95% of the QGraphicsView's size.

              FlotisableF Offline
              FlotisableF Offline
              Flotisable
              wrote on last edited by
              #6

              @canellas
              I put an example on github
              is this what you want?

              1 Reply Last reply
              1

              • Login

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