Results 1 to 10 of 10

Thread: QPainter drawLine() doesn't draw the line with the right width (Is this a bug?)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2013
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default QPainter drawLine() doesn't draw the line with the right width (Is this a bug?)

    Hello,

    I'm having some trouble just to draw a single horizontal line with a QPainter. The following code and its output are self-explanatory:

    Qt Code:
    1. // Creates a simple image
    2. QImage img(200, 200, QImage::Format_ARGB32_Premultiplied);
    3. img.fill(Qt::transparent);
    4. QPainter p(&img);
    5. // Sets a pen with a width of 3 pixels
    6. p.setPen(QPen(QColor(255, 255, 0), 3, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
    7. // Draws the line
    8. p.drawLine(50, 50, 100, 50);
    9. // Saves the image
    10. img.save("toto.png");
    To copy to clipboard, switch view to plain text mode 

    The foo.png image generated does have a an horizontal line, but with a width of 2 pixels instead of 3.

    I guess this is a bug, as I clearly don't see what I've done wrong. I had this issue on my program I'm working on, in which I had lines with the wrong width... Then I wrote this simple code just to check. And it looks like a Qt bug. What do you think? Is this a known issue? I'm using Qt 5.0.2 with gcc 4.7.2 on Windows 8.

    Thanks!
    Last edited by Sébastien; 7th July 2013 at 16:11.

Similar Threads

  1. Draw line on image using QPainter
    By Qt Coder in forum Qt Programming
    Replies: 29
    Last Post: 11th August 2015, 12:09
  2. Qpainter draw line
    By waiter in forum Newbie
    Replies: 2
    Last Post: 26th April 2013, 09:17
  3. How to draw a line with tiled images with QPainter?
    By MadBear in forum Qt Programming
    Replies: 5
    Last Post: 25th July 2011, 06:36
  4. Replies: 1
    Last Post: 29th June 2011, 16:52
  5. QPainter doesn't seem to draw QImage
    By Denarius in forum Qt Programming
    Replies: 7
    Last Post: 3rd March 2009, 14:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.