Results 1 to 7 of 7

Thread: How to rotate only line and not the text?

  1. #1
    Join Date
    Jan 2013
    Posts
    22
    Thanked 3 Times in 2 Posts
    Qt products
    Qt/Embedded

    Post How to rotate only line and not the text?

    Hi All,
    i want to rotate a line.and in front of line letter say 's' is there.
    i want to keep angle for text 's' as 0(i.e. do not want to rotate it and only line to be rotated with letter 's' in front of it).how to do it?
    if we use Q painter's rotate property when line is rotating letter 's' is also rotating





    Thanks,
    sanujas

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

    Default Re: How to rotate only line and not the text?

    Reverse the rotation transformation before painting the letter. You can also use QPainter::save() and QPainter::restore() to help revert the painter to previously saved state.
    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. #3
    Join Date
    Jan 2013
    Posts
    22
    Thanked 3 Times in 2 Posts
    Qt products
    Qt/Embedded

    Default Re: How to rotate only line and not the text?

    Means do you want to say
    i should add following lines before painting text?
    painter.save;
    painter.rotate(-angle)//angle is int
    painter.drawText(50, 0, "s");//for e.g.
    painter.restore;
    i was tried to use painter.save and painter.restore as above
    ok let me try 2nd line which i was not done.


    Thanks,
    sanujas

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

    Default Re: How to rotate only line and not the text?

    Well... either do this:

    Qt Code:
    1. painter.rotate(angle);
    2. painter.drawLine(...);
    3. painter.rotate(-angle);
    4. painter.drawText(...);
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. painter.save();
    2. painter.rotate(angle);
    3. painter.drawLine(...);
    4. painter.restore();
    5. painter.drawText(...);
    To copy to clipboard, switch view to plain text mode 
    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.


  5. #5
    Join Date
    Jan 2013
    Posts
    22
    Thanked 3 Times in 2 Posts
    Qt products
    Qt/Embedded

    Default Re: How to rotate only line and not the text?

    Using first option given by you i could able to stop rotating letter.now i am trying to write text infront of line which rotates from 0 to 360 deg. i used the formula for points on circumference of a circle(x=origin+radius*cos(angle),y=origin+radius* sin(angle)).but it is getting some offset and line and text are not synchronised.e.g. if line is in 1st quadrant the letter will be in any other quadrant.so how to nullify that offset?

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

    Default Re: How to rotate only line and not the text?

    It's pure math, there isn't much I can help you here with. You just need to correct your calculations.
    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. #7
    Join Date
    Jan 2013
    Posts
    22
    Thanked 3 Times in 2 Posts
    Qt products
    Qt/Embedded

    Default Re: How to rotate only line and not the text?

    yah you are right,it was related to maths calculation only, i was thinking something yet remained to do in QT.My problem got solved.

    Thank,
    sanujas

Similar Threads

  1. Line doesnt Rotate on its center
    By 21altf in forum Newbie
    Replies: 1
    Last Post: 1st November 2011, 01:04
  2. Reading a text line per line
    By Momergil in forum Newbie
    Replies: 0
    Last Post: 19th July 2011, 15:46
  3. how can i rotate a text ?
    By savaliya_ambani in forum Qt for Embedded and Mobile
    Replies: 9
    Last Post: 11th June 2010, 12:52
  4. How to select a line of text
    By benlyboy in forum Newbie
    Replies: 6
    Last Post: 25th April 2010, 23:56
  5. How to get text of last line only in QTextEdit?
    By rajesh in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2006, 13:37

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
  •  
Qt is a trademark of The Qt Company.