Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't seem to draw from the center of two rectangles....
Qt 6.12 LTS is out! See what's new in the release blog

Can't seem to draw from the center of two rectangles....

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 4.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.
  • M Offline
    M Offline
    mpergand
    wrote on last edited by mpergand
    #2
    QPoint fCP((fRect.width()/2),(fRect.height()/2));
    QPoint sCP((sRect.width()/2), (sRect.height()/2));
    

    This draw a single point :)
    You draw the first rectangle two times.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeJoe_000
      wrote on last edited by
      #3
      This post is deleted!
      1 Reply Last reply
      0
      • J Offline
        J Offline
        JoeJoe_000
        wrote on last edited by
        #4

        I believe you're mistaken sir.

        QPoint doesnt draw anything it holds values for a point, points that can be used to draw a line.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mpergand
          wrote on last edited by
          #5
          QPoint fCP((fRect.width()/2),(fRect.height()/2));
          QPoint sCP((sRect.width()/2), (sRect.height()/3));
          

          Now it draws a line.
          At first glance i don't see the point, but it's there ;)

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JoeJoe_000
            wrote on last edited by JoeJoe_000
            #6

            awww man...what world are you from?? :'(

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JoeJoe_000
              wrote on last edited by
              #7

              Please somebody help.

              D 1 Reply Last reply
              0
              • J JoeJoe_000

                Please somebody help.

                D Offline
                D Offline
                Devopia53
                wrote on last edited by Devopia53
                #8

                @JoeJoe_000

                QPoint fCP((fRect.width()/2),(fRect.height()/2));
                QPoint sCP((sRect.width()/2), (sRect.height()/2));
                

                The fCP and sCP are the same point(50, 25) as @JoeJoe_000 mentioned. So it does not look good, but it appears as a dot on the screen.

                If you want to draw a line connecting the centers of two rectangles, try the following:

                painter.drawLine(fRect.center(), sRect.center());
                
                1 Reply Last reply
                2
                • J Offline
                  J Offline
                  JoeJoe_000
                  wrote on last edited by JoeJoe_000
                  #9

                  Thanks a lot. I didnt know about those two functions. I finally figured out my idiocy. Thanks.

                  //This does the same thing as painter.drawLine(fRect.center(), sRect.center());
                     QPoint pCP((parent.width()/2)+parent.left(),(parent.height()/2)+parent.top());
                      QPoint cCP((child.width()/2)+child.left(), (child.height()/2)+child.top());
                  
                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JoeJoe_000
                    wrote on last edited by
                    #10

                    Do you know how to specify which object/shape is at a high layer (drawing over) or lower layer (drawing under)?

                    jsulmJ 1 Reply Last reply
                    0
                    • J JoeJoe_000

                      Do you know how to specify which object/shape is at a high layer (drawing over) or lower layer (drawing under)?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @JoeJoe_000 I would say what you draw first is lower layer

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        Hi
                        When using QPainter there is no layers.
                        So what you draw last, will be on top.

                        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
                        • Unsolved