QGraphicsLineItem line width
Can somebody explain how to draw a QGraphicsLineItem's line with a width of 1 pixel?
I have set the painter's pen width to 1
but the line width is grater than 1.
If I draw line on a QLabel or QWidget paint methods it works ok
line width is relative to the "distance" between the view and the scene. More you zoom, more the width grows. If you want the line to be always 1, independently from the "distance", you should set the pen width to 0.
Look at the QPen::setWidth documentation.
Thanks for suggestion but it seams I get the same display.
Anyway I have no zoom set (yet).
On the ruler I get the correct display (1 pixel) and on the scene ...?!
Maybe it is the result of anti-aliasing?
What type of "p" variable in your code?
void GuideItem::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget * )
How can I modify this aliasing feature/setting?
[quote author="Doru" date="1291103107"]void GuideItem::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget * )
Is GuideItem inherited from QGraphicsLineItem? If "yes" then why do you paint line yourself? Does call to QGraphicsLineItem::paint() produce the same result?
Yes , it produces the same result.
I paint it myself because I want to modify line color when selected.
As I said above, I think that it is anti-aliasing effect. Try to play with QPainter settings:
void QPainter::setRenderHint ( RenderHint hint, bool on = true )
I did'n succeed with render hints.
Can this problem appear because it is a graphic item?
Sorry, no answer. Try to go step-by-step in debug mode in Qt library code (for example, set break-point in QPainter::drawLine() function). Maybe you will understand what happens.