Results 1 to 10 of 10

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

  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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

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

    If it is a bug (I don't know, I have not seen any evidence) then it does not occur on:
    • Linux under Qt 4.8.4 or 5.1.0 (GCC 4.6.3)
    • Windows XP under Qt 4.8.4 (GCC 4.4)
    • Windows 8 under Qt 4.8.4 (GCC 4.4)

  3. #3
    Join Date
    Mar 2013
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows

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

    Thank you for your reply.

    Well I upgraded to Qt 5.1, gcc 4.8.0, and the problem is still here.

    I guess it's a real bug, I'll report it when I have time. But I find strange that such an obvious bug exists.

    Can anyone with the same config try to check if the they encounter the same issue? Because I still find it hard to believe^^

    Thanks!

  4. #4

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

    I have seen this occur when using the OpenGL paint engine (which it doesn't look like you're doing) on specific hardware. I have never seen it occur with the raster paint engine in Qt 4.8 - 5.1.

  5. #5
    Join Date
    Mar 2013
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows

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

    Thanks for your reply.

    I checked and I indeed use the Raster paint engine...

    I've kept investigating though. I created a new empty project in which I tested the same code. I found out that if I compile in debug mode, the line has the correct width, but if I compile in release, it doesn't... I compiled in release mode in my first project too when I discovered the issue. This makes me think it's a real bug.

    Still under Qt 5.1, gcc 4.8.0, Windows 8.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

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

    I've just reproduced the debug/release difference on Windows 7 32-bit with the official 5.1 MingW OpenGL offline installer version.
    Reported as https://bugreports.qt-project.org/browse/QTBUG-32387

    BTW, I hope you don't think I am stealing your thunder by reporting the bug

  7. #7
    Join Date
    Mar 2013
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows

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

    Ok, so I'm not the only with the issue.

    But it seems like we reported the issue at the same time (https://bugreports.qt-project.org/browse/QTBUG-32376). I guess only one bug report should be open. I think your bug report is more complete than mine, so I intend to withdraw mine. Please confirm so we don't withdraw both our report at the same time

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

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

    Cool. Didn't see yours despite a search. I'll add a comment to mine that points to this thread and your bug if you wish to close it.

  9. #9
    Join Date
    Mar 2013
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Windows

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

    Ok, I see my duplicate report has been closed.

    That works fine for me, thanks!

  10. #10
    Join Date
    Apr 2014
    Posts
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

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

    further to this:
    Im using Ubuntu 13.10 64bit QT5
    I have the same problem, the line width is ignored by qpainter.
    Also I think qpainter must take a copy of the pen because if I change the color on the pen that too is ignored, I have to change color with setcolor on the painter.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.