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. Exact correct size needed
Forum Updated to NodeBB v4.3 + New Features

Exact correct size needed

Scheduled Pinned Locked Moved Solved General and Desktop
33 Posts 7 Posters 5.0k 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.
  • O Offline
    O Offline
    ollarch
    wrote on last edited by
    #23

    So you want to display a rect only on the first view? You could create two scenes and two views and add only the rect into the first one. If the second view is some kind of "only selected view" you can take the rect position and size to crop the image and set it to the QGraphicsPixmapItem on the second scene.

    JonBJ 1 Reply Last reply
    0
    • O ollarch

      So you want to display a rect only on the first view? You could create two scenes and two views and add only the rect into the first one. If the second view is some kind of "only selected view" you can take the rect position and size to crop the image and set it to the QGraphicsPixmapItem on the second scene.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #24

      @ollarch said in Exact correct size needed:
      Hi @ollarch. Your post has just crossed with the latest UPDATE I have typed into my post above!

      So you want to display a rect only on the first view? You could create two scenes and two views and add only the rect into the first one.

      Nooo, I don't think so! 2 scenes?! Just for a shape on a view?

      I'm pretty sure now that I understand a bit more that what I am doing via QGraphicsView::drawForeground() is the correct, cheapest way to draw a temporary foreground shape --- which is not an object on the scene --- to follow the mouse.

      You can see there that I am getting so excited now that I understand layers --- background -> any graphics objects -> foreground --- plus the fact that QGraphicsView draws its own layers, QGraphicsView::drawForeground

      Reimplement this function to provide a custom foreground for this view.

      The default implementation fills rect using the view's foregroundBrush. If no such brush is defined (the default), the scene's drawForeground() function is called instead.

      So I now think I ought best move the map pixmap out from being a graphics object and into the scene's background layer instead. I am enjoying this as I begin to understand :)

      1 Reply Last reply
      0
      • O Offline
        O Offline
        ollarch
        wrote on last edited by
        #25

        If I understand it. When the mouse enters the view you want to display a rect (or circle) centered to the mouse position?

        JonBJ 1 Reply Last reply
        0
        • O ollarch

          If I understand it. When the mouse enters the view you want to display a rect (or circle) centered to the mouse position?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #26

          @ollarch
          Yes. (Only a touch more complex than that: it has to map to nearest rect/circle/shape where the map is notionally divided into a grid of distinctly-located shapes, rather than continuous, and "snap" to there. But that is a detail.) And this shape must only be drawn on the view where the mouse is being moved; it does not belong to the scene, and if there were multiple views it must not appear in views other than the one with the mouse move. That's why it has to be view-based, not scene-based.

          But I am already at this point now, I have achieved what I need, using QGraphicsView::drawForeground() :)

          1 Reply Last reply
          0
          • O Offline
            O Offline
            ollarch
            wrote on last edited by
            #27

            Hi,

            Do you have a second view, for what?

            JonBJ 1 Reply Last reply
            0
            • O ollarch

              Hi,

              Do you have a second view, for what?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #28

              @ollarch
              As I wrote earlier, presently I do not, but there is no reason I should not introduce one at a later date. One could have multiple views onto the same scene, so that user could see different areas of map in different windows (views) if desired.

              At which point I would only want the foreground shape following the user's mouse to appear in the one view where he is currently moving the mouse, not any other views (even if they happened to observe the same area of the scene as the current mouse view window).

              This is why the shape should be drawn in QGraphicsView::drawForeground(), which is local to one view, not either in QGraphicsScene::drawForeground() nor via placing a QGraphicsItem on the scene (both of these would show the shape in all views observing that area of the scene, which I do not want.)

              As I say, I have this working well now :)

              1 Reply Last reply
              0
              • O Offline
                O Offline
                ollarch
                wrote on last edited by
                #29

                I was only thinking on a another way to to this.

                JonBJ 1 Reply Last reply
                1
                • O ollarch

                  I was only thinking on a another way to to this.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #30

                  @ollarch
                  :) No problem. You have really helpful getting me going on gfx scene + view.

                  I am finding that QGraphicsView::drawForeground() is the best way to draw a temporary shape on (the top of) the given view (only). I came across that somewhere (but can't remember where) as the suggested way to achieve this best.

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    ollarch
                    wrote on last edited by
                    #31

                    Happy to help.
                    ;D

                    1 Reply Last reply
                    1
                    • P Offline
                      P Offline
                      paulrishabh31
                      Banned
                      wrote on last edited by paulrishabh31
                      #32
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        spiceagent11
                        wrote on last edited by
                        #33

                        Think on a CAD software. The schematic have to keep the units regardless of the zoom applied or the rotation of the view. You can rotate the view, zoom it, ... but when you ask the view to map the mouse position into scene coordinates, this coordinates will still be the same pixel position.

                        Regards
                        https://vidmateapp.win Owner

                        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