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. line to pixel Scene
Forum Updated to NodeBB v4.3 + New Features

line to pixel Scene

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 3.9k 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.
  • AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by
    #1

    Hello everyone.
    First of all thanks a lot for helping me and reading this post.

    i have some lines in scene. I have their coordinates in pixels (XStart YStart XEnd YEnd).

    Now I would like to transform this line to a QImage con my resolution (for example 0.1 meter/pixel)
    Is there any function or class that it can help me?

    Thanks a lot!

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

      Hi
      Its very unclear what you mean. (for me)

      say we have line from 100,100 to 400,400

      Now you want to paint the same line on a QImage?

      The QImage also use pixels so you can just draw it.

      AlvaroSA 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        Its very unclear what you mean. (for me)

        say we have line from 100,100 to 400,400

        Now you want to paint the same line on a QImage?

        The QImage also use pixels so you can just draw it.

        AlvaroSA Offline
        AlvaroSA Offline
        AlvaroS
        wrote on last edited by
        #3

        @mrjj hi again friend. Thanks for replying.

        Yes, i have the coordinates in pixels.
        And I want to draw the line in an image. Which function have I to use?

        O 1 Reply Last reply
        0
        • AlvaroSA AlvaroS

          @mrjj hi again friend. Thanks for replying.

          Yes, i have the coordinates in pixels.
          And I want to draw the line in an image. Which function have I to use?

          O Offline
          O Offline
          onek24
          wrote on last edited by onek24
          #4

          @AlvaroS

          Hey,

          you can try the drawLine function from the QPainter:

          QImage image = ...;
          QPainter painter(&image);
          painter.drawLine(x1, y1, x2, y2);
          
          // If the painter cant draw on an image directly, try to draw on the pixmap of the image:
          QPixmap pix = QPixmap::fromImage(image);
          QPainter painter(&pix);
          painter.drawLine(x1, y1, x2, y2);
          image = pixmap.toImage();
          
          AlvaroSA 2 Replies Last reply
          3
          • O onek24

            @AlvaroS

            Hey,

            you can try the drawLine function from the QPainter:

            QImage image = ...;
            QPainter painter(&image);
            painter.drawLine(x1, y1, x2, y2);
            
            // If the painter cant draw on an image directly, try to draw on the pixmap of the image:
            QPixmap pix = QPixmap::fromImage(image);
            QPainter painter(&pix);
            painter.drawLine(x1, y1, x2, y2);
            image = pixmap.toImage();
            
            AlvaroSA Offline
            AlvaroSA Offline
            AlvaroS
            wrote on last edited by
            #5

            @onek24 Thanks my friend!

            i can use that, but how can I do for using a resolution. For example 0.01 meter/pixel for drawing the line?!

            1 Reply Last reply
            0
            • O onek24

              @AlvaroS

              Hey,

              you can try the drawLine function from the QPainter:

              QImage image = ...;
              QPainter painter(&image);
              painter.drawLine(x1, y1, x2, y2);
              
              // If the painter cant draw on an image directly, try to draw on the pixmap of the image:
              QPixmap pix = QPixmap::fromImage(image);
              QPainter painter(&pix);
              painter.drawLine(x1, y1, x2, y2);
              image = pixmap.toImage();
              
              AlvaroSA Offline
              AlvaroSA Offline
              AlvaroS
              wrote on last edited by
              #6

              @onek24 said:

              @AlvaroS

              Hey,

              you can try the drawLine function from the QPainter:

              QImage image = ...;
              QPainter painter(&image);
              painter.drawLine(x1, y1, x2, y2);
              
              // If the painter cant draw on an image directly, try to draw on the pixmap of the image:
              QPixmap pix = QPixmap::fromImage(image);
              QPainter painter(&pix);
              painter.drawLine(x1, y1, x2, y2);
              image = pixmap.toImage();
              

              @AlvaroS said:

              @onek24 Thanks my friend!

              i can use that, but how can I do for using a resolution. For example 0.01 meter/pixel for drawing the line?!

              i have just used this:

                  QPen line_res;
                  line_res.setColor(Qt::black);
                  line_res.setWidthF(resolution);
                  painter.setPen(line_res);
              

              But width function is not the resolution in m/px...

              1 Reply Last reply
              0
              • AlvaroSA Offline
                AlvaroSA Offline
                AlvaroS
                wrote on last edited by
                #7

                For example in the first image here: http://doc.qt.io/qt-4.8/coordsys.html

                how can I set the size of each square(the size in meter of each pixel)?
                @mrjj @onek24

                O 1 Reply Last reply
                0
                • jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  If you say 0.01 meter per pixel, then a 2.5 meter line would need 2.5 / 0.01 = 250 pixel

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

                  AlvaroSA 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    If you say 0.01 meter per pixel, then a 2.5 meter line would need 2.5 / 0.01 = 250 pixel

                    AlvaroSA Offline
                    AlvaroSA Offline
                    AlvaroS
                    wrote on last edited by
                    #9

                    @jsulm Yes! But I do not how to set this resolution of each pixel (each square)

                    1 Reply Last reply
                    0
                    • jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      You cannot as far as I know. It is something related to your application. QPainter does not know any thing about meter it uses pixels, so it is your job to translate meters to pixels.

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

                      1 Reply Last reply
                      0
                      • AlvaroSA AlvaroS

                        For example in the first image here: http://doc.qt.io/qt-4.8/coordsys.html

                        how can I set the size of each square(the size in meter of each pixel)?
                        @mrjj @onek24

                        O Offline
                        O Offline
                        onek24
                        wrote on last edited by onek24
                        #11

                        @AlvaroS

                        Each "square" in the qt matrix is 1, Its the basic unit. Usually you cant work directly with pixel-metric size combinations. The size of an actual pixel is defined by your display, lets say your display has a DPI(Dots per inch) of 100, that means it has 100 dots on 1 inch lench, which is approximately 40 pixels per centimeter. So if you want to draw a line which has a physical length of, lets say 1 meter, then you have to take your DPI, make it dots per centimeter by division of roughly 2,54, and then multiply it by 100 to make it dots per meter. That would be the length of your line. You can do these calculation for width or whatever. Afaik if the Scene isn't scaled, 1 pixel or square on the qt scene is 1 physical pixel. So drawing would be enough, as long as you dont scale the qt scene.

                        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