Results 1 to 5 of 5

Thread: QGLWidget renderText rotation

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face QGLWidget renderText rotation

    I am trying to rotate some text for a 2-D plot I am making. I am trying to put this in a portion of my left viewport so that it runs from bottom to top. The bottom of the letters will face the inside of the plot. I am designing this program in Qt and using a QGLWidget. Here is the snipet of my code I have:

    Qt Code:
    1. glMatrixMode( GL_PROJECTION );
    2. glLoadIdentity( );
    3. glOrtho( -10.0, 10.0, -10.0, 10.0, -10.0, 10.0 );
    4. glMatrixMode( GL_MODELVIEW );
    5. glLoadIdentity( );
    6. glViewport( ( leftMarginWidth / 4.0 ), 0.0, ( leftMarginWidth / 4.0 ), winHeight );
    7. glScissor( ( leftMarginWidth / 4.0 ), 0.0, ( leftMarginWidth / 4.0 ), winHeight );
    8. mpQgl->qglColor( mLeftLabelColor );
    9. glPushMatrix( );
    10. mpQgl->renderText( 0.0, 0.0, 0.0, mLeftLabel );
    11. glRotated( 90.0, 0.0, 0.0, 1.0 );
    12. glPopMatrix( );
    To copy to clipboard, switch view to plain text mode 

    mLeftLabel is a QString of what holds the label.
    leftMarginWidth is a double holding the width of the left margin. I allow for a title to be in the first 1/4 of the margin, followed by the label in the 2nd quarter of the margin, followed by the actual axis tick marks and corresponding values in the 2nd half of the margin.
    mpQgl is a pointer to the QGLWidget I am drawing in.
    I have 3 different viewports on each margin and margins on all 4 sides and then the viewport for the plot in the middle. So the only viewport I want rotated is the viewport with the axis label on the left side. I have tried moving the rotate before the render text and also moving the renderText outside the push/pop matrix, but nothing helps. The text always renders in a horizontal manner inside the middle of the viewport I created. Here is a link to renderText.

    Thanks for all your help in trying to help me figure out why my text isn't rotating. If you need more information, please let me know what it is I am missing so I can try to find what you need to further help me.

  2. #2
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget renderText rotation

    Does anybody have any ideas whether renderText actually rotates the text or keeps the text in a horizontal position but just moves the test with the object? I still have not been able to figure this out. Thanks!

  3. #3
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Re: QGLWidget renderText rotation

    Since I cannot figure how to get renderText to rotate the text I tried to use a QPainter to draw my rotated text. Here is the code I use:

    Qt Code:
    1. mpLabelPainter = new QPainter( );
    2. mpLabelPainter->begin( mpQgl );
    3. mpLabelPainter->setClipping( true );
    4. mpLabelPainter->setMatrixEnabled( true );
    5. mpLabelPainter->setWindow( 0, 0, winWidth, winHeight );
    6. mpLabelPainter->setViewport( QRect( ( leftMarginWidth / 4.0 ), 0.0, ( leftMarginWidth / 4.0 ), winHeight ) );
    7. mpLabelPainter->setClipRect( QRect( ( leftMarginWidth / 4.0 ), 0.0, ( leftMarginWidth / 4.0 ), winHeight ), Qt::ReplaceClip );
    8. QMatrix matrix;
    9. matrix.rotate( 270.0 );
    10. mpLabelPainter->setMatrix( matrix, true );
    11. mpLabelPainter->setFont( textFont );
    12. mpLabelPainter->setPen( Qt::black );
    13. mpLabelPainter->drawText( QPointF( 0.0, 0.0 ), mLeftLabel );
    14. mpLabelPainter->end( );
    To copy to clipboard, switch view to plain text mode 

    mpQgl is a pointer to my QGLWidget.
    leftMarginWidth is the width of my left margin. I want to render this text inside the 2nd quarter of my left margin which is why I start the rectangle at 1/4 the way over and the width is only 1/4 of the margin width.
    winWidth and winHeight are the height and width of the QGLWidget.
    textFont is the font used in the program.
    mLeftLabel is the QString I want to write to the screen.

    When I run this code, the 2nd half of my margin turns to a white block. Why is the QPainter overwritingn this area when I set its clip and viewport in the 2nd quarter of the margin, not the 2nd half. The block turns white when I just call the new QPainter, begin, and end lines. If I comment out every other line but those three, I get the white rectangle in the wrong spot. If I comment out all the code, then nothing behaves incorrectly. I should also mention that text is never being drawn on any combination of lines of code. Does it look as if something is working wrong? Thanks for your help in trying to help me fix this!

  4. #4
    Join Date
    Jul 2007
    Location
    California, USA
    Posts
    62
    Thanks
    17
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGLWidget renderText rotation

    I also tried to rotate the text and couldn't. Here is what I found out:

    You cannot use rotate and renderText and it is by design and has historical reasons.

    You do need to use QPainter, apply a transformation, and use the QPainter::drawText function to do it.

    However, you need to do these things:
    1) you need to call setAutoFillBackground(false) on the QGLWidget so that QPainter::begin() won't call glClear().
    2) you need to turn off setAutoBufferSwap so that QPainter::end() won't swap the buffers
    3) you need to avoid doing any GL calls in between QPainter::begin and QPainter::end.

    I haven't had a chance to try it yet. Hope this works for you.

  5. The following user says thank you to ntp for this useful post:

    ToddAtWSU (19th September 2007)

  6. #5
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget renderText rotation

    About 10 months ago I worked on a bitmap text in which I just figured out how to render the letters at a rotated angle so it would work in my plot. But these ideas are great as I would love to use the QPainter instead of my bitmap text to render onto the plots at sometime. Thanks for the pointers and maybe I will try them out sometime soon.

Similar Threads

  1. renderText
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 24th August 2006, 13:29
  2. QGLWidget renderText()
    By ToddAtWSU in forum Qt Programming
    Replies: 8
    Last Post: 21st July 2006, 13:20
  3. QGLWidget renderText
    By Rayven in forum Qt Programming
    Replies: 2
    Last Post: 14th July 2006, 21:02
  4. QGLWidget updateGL()
    By Lele in forum Qt Programming
    Replies: 7
    Last Post: 30th May 2006, 15:08
  5. QGLWidget renderText problem
    By mbjerkne in forum Qt Programming
    Replies: 1
    Last Post: 7th April 2006, 21:35

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.