PDA

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



Sébastien
7th July 2013, 17:01
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:


// Creates a simple image
QImage img(200, 200, QImage::Format_ARGB32_Premultiplied);
img.fill(Qt::transparent);
QPainter p(&img);
// Sets a pen with a width of 3 pixels
p.setPen(QPen(QColor(255, 255, 0), 3, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
// Draws the line
p.drawLine(50, 50, 100, 50);
// Saves the image
img.save("toto.png");

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!

ChrisW67
8th July 2013, 01:19
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)

Sébastien
10th July 2013, 11:19
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!

Aztral
10th July 2013, 19:54
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.

Sébastien
11th July 2013, 13:13
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.

ChrisW67
12th July 2013, 02:40
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

Sébastien
12th July 2013, 09:26
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 :)

ChrisW67
12th July 2013, 10:40
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.

Sébastien
12th July 2013, 11:12
Ok, I see my duplicate report has been closed.

That works fine for me, thanks!

mikejuk
2nd April 2014, 04:22
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.