About QPixmap and QPen



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


  • Moderators

    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



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


  • Moderators

    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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.