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 Becomes Large Square
Forum Update on Monday, May 27th 2025

Line Becomes Large Square

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 974 Views
  • 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.
  • qt27Q Offline
    qt27Q Offline
    qt27
    wrote on last edited by
    #1

    When I draw a line with length 1, i.e. the start point and end point are the same, and then I zoom, the line suddenly becomes a large square of size 10x10. When the line has a length of 2+ then it stays just 1 pixel wide. Why is this happening and how to I prevent it?

    As background info, I am trying to use this to draw individual pixels.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      What kind of drawing are you talking about? QPainter, QPainterPath, QGraphicsItem, OpenGL?

      1 Reply Last reply
      1
      • qt27Q Offline
        qt27Q Offline
        qt27
        wrote on last edited by
        #3

        QGraphicsItem on a QScene.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Devopia53
          wrote on last edited by
          #4

          Hi.

          I think that there are some bug if the same starting point and end point.
          But you should do something like this:

          QPen    pen(Qt::red);
          pen.setWidth(2); // If it stay just 1 pixel wide, set 1
          pen.setCosmetic(true);
          yourScene->addLine(0, 0, 0, 0, pen);
          
          qt27Q 1 Reply Last reply
          0
          • D Devopia53

            Hi.

            I think that there are some bug if the same starting point and end point.
            But you should do something like this:

            QPen    pen(Qt::red);
            pen.setWidth(2); // If it stay just 1 pixel wide, set 1
            pen.setCosmetic(true);
            yourScene->addLine(0, 0, 0, 0, pen);
            
            qt27Q Offline
            qt27Q Offline
            qt27
            wrote on last edited by
            #5

            @Devopia53 setting cosmetic to true does keeps the line with length 1 as 1 pixel. However, it doesn't zoom anymore. That's of course the purpose of cosmetic but I still need it to zoom. So if I zoom in 16x then my line of length 1 should be 16 screen pixels wide. But at the moment when I turn off cosmetic the lines with length 1 become like 80 pixels wide. That happens as soon as I zoom in/out (before it has the correct size).

            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