Results 1 to 10 of 10

Thread: problem translating & rotating text

  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default problem translating & rotating text

    Hi, i'm using Qt4.1.4
    I have three lines forming a triange.
    I want to label these lines s1, s2, s3 at the midpoint of each line, rotated to the angle of the line.
    Qt Code:
    1. void edpForm::paintEvent(QPaintEvent *event)
    2. {
    3. double angle;
    4. QPainter painter( this );
    5.  
    6. for( n = 0; n < paintLines.count(); ++n )
    7. {
    8. k = paintLines[n];
    9. temp = k.split( "," );
    10. xs = temp[0].toInt( &ok );
    11. ys = temp[1].toInt( &ok );
    12. xe = temp[2].toInt( &ok );
    13. ye = temp[3].toInt( &ok );
    14. painter.drawLine( xs, ys, xe, ye );
    15. }
    16. for( n = 0; n < paintLabels.count(); ++n )
    17. {
    18. k = paintLabels[n];
    19. temp = k.split( "," );
    20. xs = temp[0].toInt( &ok );
    21. ys = temp[1].toInt( &ok );
    22. angle = temp[2].toDouble( &ok );
    23. painter.translate( xs, ys );
    24. painter.rotate( angle );
    25. painter.drawText( 0, 0, temp[3] );
    26. //painter.drawText( xs, ys, temp[3] );
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 
    With the code as shown, I get the label s1, rotated to the angle of the line and at the midpoint of the line. The other two lines are not labeled.

    If I option out the 3 lines above the optioned out line and activate the bottom line, I get each line labled at their midpoints, but the labels are not rotated.

    This tells me, that the data is OK., so there must be somthing wrong with my code. Help would be appreciated.

    I am having a great deal of trouble with the switch from Qt3 to Qt4 dealing with graphics, so I am being very verbose

    thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem translating & rotating text

    Try this

    Qt Code:
    1. void edpForm::paintEvent(QPaintEvent *event)
    2. {
    3. double angle;
    4. QPainter painter( this );
    5.  
    6. for( n = 0; n < paintLines.count(); ++n ) {
    7. k = paintLines[n];
    8. temp = k.split( "," );
    9. xs = temp[0].toInt( &ok );
    10. ys = temp[1].toInt( &ok );
    11. xe = temp[2].toInt( &ok );
    12. ye = temp[3].toInt( &ok );
    13. painter.drawLine( xs, ys, xe, ye );
    14. }
    15.  
    16. for( n = 0; n < paintLabels.count(); ++n ) {
    17. k = paintLabels[n];
    18. temp = k.split( "," );
    19. xs = temp[0].toInt( &ok );
    20. ys = temp[1].toInt( &ok );
    21. angle = temp[2].toDouble( &ok );
    22.  
    23. painter.save();
    24.  
    25. painter.translate( xs, ys );
    26. painter.rotate( angle );
    27. painter.drawText( 0, 0, temp[3] );
    28. //painter.drawText( xs, ys, temp[3] );
    29.  
    30. painter.restore();
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: problem translating & rotating text

    Thanks, but adding "painter.repaint" did not make any diference.
    I will try to send a screen shotshot, but I don't knowif this is the way to do it.
    [IMG]/home/pete/Programs/pmProgram/snapshot6.png[/IMG]
    anyway, below is the code for the"paintEvent" trigger.
    Qt Code:
    1. void edpForm::slotPaintItems( QStringList list )
    2. {
    3. paintLines = list[0].split( "|" );
    4. paintLabels = list[1].split( "|" );
    5. edpForm::update();
    6. }
    To copy to clipboard, switch view to plain text mode 
    I tried "repaint" in place of "update" no diference.

    I may have 15 or 20 items that I want painted and the combination of items will very depending on where the trigger is called. They will be in order with a "null" string for those not to be printed. Say I want to paint the lines without the labels. Is the procedure I have used here appropiate?

    Thanks.

    I

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem translating & rotating text

    but adding "painter.repaint" did not make any diference.
    It is painter.restore and not painter.repaint

    I will try to send a screen shotshot, but I don't knowif this is the way to do it.
    [IMG]/home/pete/Programs/pmProgram/snapshot6.png[/IMG]
    You can upload your png at http://imageshack.us and then give the link here like:

    [IMG]link[/IMG]

    Say I want to paint the lines without the labels. Is the procedure I have used here appropiate?
    I think its fine. But you will need to call repaint() in order to see changes immediately.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem translating & rotating text

    Quote Originally Posted by munna
    You can upload your png at http://imageshack.us and then give the link here like:
    Or simply click "Manage Attachments" button below the editor.

  6. #6
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: problem translating & rotating text

    Thanks, I do have painter.restore in my code. I miss typed it in my post sorry. When I ran the program
    Qt Code:
    1. for( n = 0; n < paintLabels.count(); ++n )
    2. {
    3. k = paintLabels[n];
    4. temp = k.split( "," );
    5. xs = temp[0].toInt( &ok );
    6. ys = temp[1].toInt( &ok );
    7. angle = temp[2].toDouble( &ok );
    8. painter.translate( xs, ys );
    9. painter.rotate( angle );
    10. painter.drawText( 0, 0, temp[3] );
    11. //painter.drawText( xs, ys, temp[3] );
    12.  
    13. painter.restore();
    14. }
    To copy to clipboard, switch view to plain text mode 
    I got the same image plus I got "Painter::restore(), unbalanced save/restore" warnings for each element painted. Now for the inmage with and without the "painter.restore()".
    [IMG][/IMG] and with the code
    Qt Code:
    1. for( n = 0; n < paintLabels.count(); ++n )
    2. {
    3. k = paintLabels[n];
    4. temp = k.split( "," );
    5. xs = temp[0].toInt( &ok );
    6. ys = temp[1].toInt( &ok );
    7. angle = temp[2].toDouble( &ok );
    8. //painter.translate( xs, ys );
    9. //painter.rotate( angle );
    10. //painter.drawText( 0, 0, temp[3] );
    11. painter.drawText( xs, ys, temp[3] );
    12.  
    13. //painter.restore();
    14. }
    To copy to clipboard, switch view to plain text mode 
    I get the image
    [IMG][/IMG] with the "painter.restore()" or with it optioned out. (name warning with it in ) I hope all this helps you.

    Thanks for the tip on images, I am not sure on its use, but if after you click on the thumbnail, you click on the image again, you get my drawing.
    Last edited by impeteperry; 3rd July 2006 at 16:42.

  7. #7
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem translating & rotating text

    I got the same image plus I got "Painter::restore(), unbalanced save/restore" warnings for each element painted.
    The warning is because for every save/restore there should be a corresponding restore/save somewhere in the code, which is what missing.

    Your code should have been

    Qt Code:
    1. for( n = 0; n < paintLabels.count(); ++n ) {
    2. k = paintLabels[n];
    3. temp = k.split( "," );
    4. xs = temp[0].toInt( &ok );
    5. ys = temp[1].toInt( &ok );
    6. angle = temp[2].toDouble( &ok );
    7.  
    8. painter.save(); //this line is missing
    9.  
    10. painter.translate( xs, ys );
    11. painter.rotate( angle );
    12. painter.drawText( 0, 0, temp[3] );
    13. //painter.drawText( xs, ys, temp[3] );
    14.  
    15. painter.restore();
    16. }
    To copy to clipboard, switch view to plain text mode 

    If you do not save and restore the painter settings for every label you want to draw the translate and rotate are carried on and is applied for the consecutive labels also, which is where you might be having problems.

  8. The following user says thank you to munna for this useful post:

    impeteperry (3rd July 2006)

  9. #8
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: problem translating & rotating text

    It works.
    [IMG][/IMG]
    Pleaase tell me where, I could find this information that demonstrates and explains this Item in simple English. I get the feeling Trolltech has hired some Microsoft programmers.

    Onwards, ever onwards.

    i was getting ready to abandon Qt.

    Thanks.

  10. #9
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem translating & rotating text

    If you look at all this logically it is all really very simple. Everything you want to know is there in the Qt Assistant. I think it is one of the best docuement ever written.

    You can download this Qt3 book and the all major concepts of drawing could still be applied for Qt4. Also, if you want you can buy this Qt4 book.

    You can also look into Qt Quarterly for reference.

    By the way, I think Trolls are better than M$ programmers.

  11. #10
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: problem translating & rotating text

    Quote Originally Posted by munna
    If you look at all this logically it is all really very simple. Everything you want to know is there in the Qt Assistant. I think it is one of the best docuement ever written.

    You can download this Qt3 book and the all major concepts of drawing could still be applied for Qt4. Also, if you want you can buy this Qt4 book.

    You can also look into Qt Quarterly for reference.

    By the way, I think Trolls are better than M$ programmers.
    I'm 80, a structural engineer and inventor. Been programming of one type or another since 1970. The switch in drawing from Qt3 to Qt4 has been the most daunting in my career. It must be the age.
    The concept of Signal & Slots is truly a great insovation.

    I had no problems in Qt3.

    From the screenshats you can tell I march to a differnt drummer. I am looking at the program as a user. The program is a substitute for CAD.
    [IMG][/IMG]

    I will look at QAssistant furthur. Thanks again. pete

Similar Threads

  1. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. Replies: 16
    Last Post: 7th March 2006, 15:57
  4. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 11:45

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.