[Qt-interest] problem in QPainter()

chandrasekar wagmare sekarwagmare at gmail.com
Fri Feb 27 06:41:03 CET 2009


hi friends,
            please help me .. i am so confused with this code :

in mainwindow.cpp (GraphicsView())

                    *line1 = new LineItem(QLineF(2,4, 132 ,160), Qt::blue,
90);   //creating an lineItem in scene

line1->setPos(374,215);                                        //settting
the line position in screen
                     scene->addItem(line1);

*in lineitem.cpp

            *LineItem::LineItem(const QLineF &line, const Qt::GlobalColor
color, qreal angle)
         : QGraphicsLineItem(line),

color(color)
//constuctor
{
       qreal value = angle;
}

void LineItem ::paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *)
{
         QTransform transform;
          painter->setPen(QColor(color));
       if(value){
             transform.translate(300,300);              // here comes the
problem
             transform.rotate(value);
             painter->setTransform(transform);
             painter->drawLine(line());
             }else{
              line().setAngle(value);
              painter->drawLine(line());
           }
}*

 in this program if the user send the the angle of rotation  the line with
the same coordinates i try to rotate ... but without this
       * transform.translate(300,300);  *i cant see the line ... more the *
              line1->setPos(374,215);          // graphicasScene
 * this value also  not working .. why ? it is defaulter to top left of the
screen ...

  but if there is no angle argument like
       *ine1 = new LineItem(QLineF(2,4, 132 ,160), Qt::blue );    *//without
angle argument

 its working fine ... i can setPos() the item ...  why? ..


              please help me ...
*-- *
CHANDRU
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090227/b3679114/attachment.html 


More information about the Qt-interest-old mailing list