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. QGraphicsRectItem moves out of the scene
Forum Updated to NodeBB v4.3 + New Features

QGraphicsRectItem moves out of the scene

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 926 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
    sayan275
    wrote on last edited by sayan275
    #1

    I have an Image Viewer, where I draw QGraphicsRectItem. The problem is the QGraphicsRectItem moves out of the scene. How can I fix the items within the sceneRect?

    I add the rect items.
    0_1547042400361_1.JPG

    I moved the item left and it went out
    0_1547042461438_2.JPG

    This completely got scrambled as I resized the viewer, ie, QGraphicsViewer
    0_1547042477731_3.JPG

    resizeEvent has been overridden by as below,

    QTransform matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
    matrix.scale(width() / sceneRect().width(), height() / sceneRect().height());
    setTransform(matrix);
    

    What could be the solution?

    raven-worxR 1 Reply Last reply
    0
    • S sayan275

      I have an Image Viewer, where I draw QGraphicsRectItem. The problem is the QGraphicsRectItem moves out of the scene. How can I fix the items within the sceneRect?

      I add the rect items.
      0_1547042400361_1.JPG

      I moved the item left and it went out
      0_1547042461438_2.JPG

      This completely got scrambled as I resized the viewer, ie, QGraphicsViewer
      0_1547042477731_3.JPG

      resizeEvent has been overridden by as below,

      QTransform matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
      matrix.scale(width() / sceneRect().width(), height() / sceneRect().height());
      setTransform(matrix);
      

      What could be the solution?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @sayan275 said in QGraphicsRectItem moves out of the scene:

      What could be the solution?

      The docs contain exactly what you are looking for

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      S 1 Reply Last reply
      2
      • raven-worxR raven-worx

        @sayan275 said in QGraphicsRectItem moves out of the scene:

        What could be the solution?

        The docs contain exactly what you are looking for

        S Offline
        S Offline
        sayan275
        wrote on last edited by
        #3

        @raven-worx Thanks for your quick suggestion. It's exactly what I'm looking for.
        Only problem is the Image Viewer(with qGraphicsScene and qgrpahicsview) is a plugin, and the Box(QGraphicsRectItem) is another plugin. Now I have to figure out way to get

        QRectF rect = scene()->sceneRect();
        

        without adding much dependency between the 2 plugins. Hopefully signal-slots does that.

        raven-worxR 1 Reply Last reply
        0
        • S sayan275

          @raven-worx Thanks for your quick suggestion. It's exactly what I'm looking for.
          Only problem is the Image Viewer(with qGraphicsScene and qgrpahicsview) is a plugin, and the Box(QGraphicsRectItem) is another plugin. Now I have to figure out way to get

          QRectF rect = scene()->sceneRect();
          

          without adding much dependency between the 2 plugins. Hopefully signal-slots does that.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @sayan275
          why is that a problem?
          When you have the item you also have the corresponding scene?!
          QGraphicsItem::scene()

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          S 1 Reply Last reply
          2
          • raven-worxR raven-worx

            @sayan275
            why is that a problem?
            When you have the item you also have the corresponding scene?!
            QGraphicsItem::scene()

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

            @raven-worx Thanks!! I got it after searching.
            But why this event is not responding, when we update the position of the rectItem by keyPress events?

            raven-worxR 1 Reply Last reply
            0
            • S sayan275

              @raven-worx Thanks!! I got it after searching.
              But why this event is not responding, when we update the position of the rectItem by keyPress events?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @sayan275 said in QGraphicsRectItem moves out of the scene:

              But why this event is not responding, when we update the position of the rectItem by keyPress events?

              what event? Do you mean QGraphicsItem::itemChange()?
              This change notifier is called in all cases whenever the position changes - it doesn't matter how it is changed.

              But it might be that you are not changing the position of the item directly?
              What i am talking about is, maybe you are just updating the rect's position (top-left corner) and let the item itself always on the position (0,0)?
              But long story short, show the code you are using to change the position of your rect item.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              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