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. About QPixmap and QPen
Forum Updated to NodeBB v4.3 + New Features

About QPixmap and QPen

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.1k 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.
  • S Offline
    S Offline
    stevewang
    wrote on last edited by
    #1

    Hi everyone.
    I'm new to Qt and I have a question about the measurement of the height of QPixmap and the width of QPen.

    So my code is like follows.

    [code]
    QPixmap image(50, 10);
    QPainter painter(image);
    QPen pen;
    pen.setWidth(10);
    painter.setPen(pen);
    painter.drawLine(0,0,50,0);
    [/code]

    But the problem is that the line did not covered all the height of the pixmap. If both of the height of the QPixmap and the width of the QPen are using one pixel as the unit size, then the whole "image" pixmap should be covered by the line right? Did I miss something? Thanks.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      From the code i see you have declared the pen but did not set it to QPainter. Have you done it but didnot post in your code here.
      See "setPen":http://qt-project.org/doc/qt-4.8/qpainter.html#setPen

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stevewang
        wrote on last edited by
        #3

        Hi p3c0,
        Thanks for your answer.
        The code was in my code.
        I just forgot to write the code here.
        I have modified my post.

        Thanks.

        [quote author="p3c0" date="1389446571"]Hi,

        From the code i see you have declared the pen but did not set it to QPainter. Have you done it but didnot post in your code here.
        See "setPen":http://qt-project.org/doc/qt-4.8/qpainter.html#setPen[/quote]

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Ok,

          Well i dont have a perfect technical explanation for this but it seems the QPainter adjusts the drawing of the line as per the line width meaning if you set the coordinates to
          @
          painter.drawLine(0,5,50,5);
          @

          which has Y coordinates of start and endpoint to be exactly half of the height of the image you get the line filling out the whole image.

          157

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stevewang
            wrote on last edited by
            #5

            Hi p3c0,

            Thanks. I did as what you said and it worked! Wierd though.
            Thanks. :)

            [quote author="p3c0" date="1389450177"]Ok,

            Well i dont have a perfect technical explanation for this but it seems the QPainter adjusts the drawing of the line as per the line width meaning if you set the coordinates to
            @
            painter.drawLine(0,5,50,5);
            @

            which has Y coordinates of start and endpoint to be exactly half of the height of the image you get the line filling out the whole image.[/quote]

            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