Results 1 to 6 of 6

Thread: problem in QLinef()

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem in QLinef()

    hi friends ,
    i need a help to clarify my doubt in QLineF() .. i dont know where i am commiting the mistake ..

    in mainwindow.cpp (QGraphicsView())
    i create a line item class ....
    Qt Code:
    1. line1 = new LineItem(QLineF(2,4, 132 ,160), Qt::blue);
    2. line1->setPos(374,215);
    To copy to clipboard, switch view to plain text mode 
    and
    in lineitem.cpp
    Qt Code:
    1. LineItem::LineItem(const QLineF &line, const Qt::GlobalColor color)
    2. color(color)
    3.  
    4. void LineItem ::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
    5. {
    6. painter->setPen(QColor(color));
    7. QReal value = 90;
    8. line().setAngle(value);
    9. painter->drawLine(line());
    10. }
    To copy to clipboard, switch view to plain text mode 

    here the line is drawn perfectly but i cant fix the angle ... its not turning in counter clockwise ... not like transform.rotate .. why ?

    please help ...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem in QLinef()

    You shouldn't change the angle like that. The paint() routine should always paint the item the same way, regardless of its actual position or rotation on the scene. If you want to rotate the line, use rotate() on the item, but still draw the item as if it was in its original direction (i.e. horizontal).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    wagmare (27th February 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QLinef()

    Quote Originally Posted by wysota View Post
    You shouldn't change the angle like that. The paint() routine should always paint the item the same way, regardless of its actual position or rotation on the scene. If you want to rotate the line, use rotate() on the item, but still draw the item as if it was in its original direction (i.e. horizontal).
    thanks for reply ..
    transform.rotate(90) is working fine ... but how can i use this QLineF::setAngle() function ... where can i implement it ..

  5. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QLinef()

    hi friends,
    i try using QTransform as

    in mainwindow.cpp (GraphicsView())
    Qt Code:
    1. line1 = new LineItem(QLineF(2,4, 132 ,160), Qt::blue, 90); //creating an lineItem in scene
    2. line1->setPos(374,215); //settting the line position in screen
    3. scene->addItem(line1);
    To copy to clipboard, switch view to plain text mode 

    in lineitem.cpp
    Qt Code:
    1. LineItem::LineItem(const QLineF &line, const Qt::GlobalColor color, qreal angle)
    2. color(color) //constuctor
    3. {
    4. qreal value = angle;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void LineItem ::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
    2. {
    3. QTransform transform;
    4. painter->setPen(QColor(color));
    5. if(value){
    6. transform.translate(300,300); // here comes the problem
    7. transform.rotate(value);
    8. painter->setTransform(transform);
    9. painter->drawLine(line());
    10. }else{
    11. line().setAngle(value);
    12. painter->drawLine(line());
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    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(x,y); i cant see the line ... more the
    Qt Code:
    1. line1->setPos(374,215); // graphicasScene
    To copy to clipboard, switch view to plain text mode 
    this value also not working .. why ? it is defaulter to top left of the screen ...

    but if there is no angle argument like
    Qt Code:
    1. line1 = new LineItem(QLineF(2,4, 132 ,160), Qt::blue ); //without angle argument
    To copy to clipboard, switch view to plain text mode 
    its working fine ... i can setPos() the item ... why? ..

    please help

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem in QLinef()

    Quote Originally Posted by wagmare View Post
    but how can i use this QLineF::setAngle() function ... where can i implement it ..
    Don't use it with QGraphicsLineItem, it doesn't make much sense to do so in this context. Rotate the item, not the line within it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    658
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QLinef()

    thanks .. i will rotate the item as
    Qt Code:
    1. QTransform transform;
    2. transform.rotate(90);
    3. line1 = new LineItem(QLineF(1,1, 132 ,160), Qt::blue, 90);
    4. scene->addItem(line1);
    5. line1->setPos(574,415);
    6. line1->setTransform(transform);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 15:38
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 13:48
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.