Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, November 2006
QGraphicsItem::paint question


Message 1 in thread


Hello,

I derive a class from the QGraphicsItem and want to implement the paint method.

Say the item are two line segments, both starting at (0,0), and going
to (1.1, 1) and (1,1) respectively.

It seems that the painter rounds the floating point number 1.1 to 1 and the
two segments coincide on the screen even if I zoom in.


   // Draw x and y axis
   painter->setPen(QPen(Qt::black, 0));
   painter->drawLine(0,0, 1, 0);
   painter->drawLine(0,0, 0, 1);

   // Draw the two segments
   painter->setPen(QPen(Qt::red, 0));
   painter->drawLine(0,0, 1.1, 1);

   painter->setPen(QPen(Qt::blue, 0));
   painter->drawLine(0,0, 1, 1);



Obviously this is a minimalistic example, and my real objects are far
more complex, but the point is that they have coordinates which are floats.

Thanks in advance,

andreas

--
 [ signature omitted ] 

Message 2 in thread

 
Andreas Fabri wrote:

> I derive a class from the QGraphicsItem and want to implement 
> the paint method.
> 
> Say the item are two line segments, both starting at (0,0), and going
> to (1.1, 1) and (1,1) respectively.
> 
> It seems that the painter rounds the floating point number 
> 1.1 to 1 and the
> two segments coincide on the screen even if I zoom in.
> 
> 
>    // Draw x and y axis
>    painter->setPen(QPen(Qt::black, 0));
>    painter->drawLine(0,0, 1, 0);
>    painter->drawLine(0,0, 0, 1);
> 
>    // Draw the two segments
>    painter->setPen(QPen(Qt::red, 0));
>    painter->drawLine(0,0, 1.1, 1);
> 
>    painter->setPen(QPen(Qt::blue, 0));
>    painter->drawLine(0,0, 1, 1);

Have you tried using one of the float based overloads such as

    painter->drawLine(QPointF(0,0), QPointF(1.1, 1));

Andre'

--
 [ signature omitted ]