Results 1 to 3 of 3

Thread: about QPainter::drawText()

  1. #1
    Join Date
    Jun 2013
    Posts
    56
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default about QPainter::drawText()

    Hi,
    The following is my test codes.

    Qt Code:
    1. char label[MAX_LABEL_LENGTH];
    2. QList<double> lMajorTicks, lMinorTicks;
    3. _pEngine -> buildTicks( _oAttribute._fStart, _oAttribute._fEnd, _nMaxMajorTickNumber, lMajorTicks, lMinorTicks );
    4.  
    5. int nCount = lMajorTicks.count();
    6. for( int i = 0; i < nCount; i ++ )
    7. {
    8. int nPos = (lMajorTicks[i]-_oAttribute._fStart)*_fScale;
    9. painter -> drawLine( nPos, _oAttribute._nMargin, nPos, _oAttribute._nMargin+_oAttribute._nMajorTickLen );
    10.  
    11. memset( label, '\0', MAX_LABEL_LENGTH );
    12. sprintf( label, _oAttribute._sMajorLabelFormat, lMajorTicks[i] );
    13. QString text = QString::fromStdString( label );
    14. QRect rc = painter -> boundingRect( QRect(0,0,0,0), Qt::AlignCenter, text );
    15. QRect qrc = QRect( nPos, _oAttribute._nMargin+_oAttribute._nMajorTickLen+15, rc.width()+10, rc.height()+10 );
    16. if( i > 0 && i < nCount-1);
    17. painter -> drawText( qrc, Qt::AlignCenter, text );
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 
    If the drawText() is commented off, the program is ok, or it crashes.
    I tried many many times but I failed.
    I don't know why and how to solve it.
    Maybe my way to use QPainter is not right?


    Thanks

    Nicho

  2. #2
    Join Date
    Jun 2013
    Posts
    56
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: about QPainter::drawText()

    Sorry, it's my fault.
    The drawLine() before goes out of the range of the device.

    Nicho

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: about QPainter::drawText()

    Btw, QString::sprintf()

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:


Similar Threads

  1. QPainter::drawText - nothing drawn
    By Vit Stepanek in forum Qt Programming
    Replies: 6
    Last Post: 23rd November 2010, 18:54
  2. QPainter drawText with different language
    By lni in forum Qt Programming
    Replies: 4
    Last Post: 11th June 2009, 19:54
  3. QPainter::drawText
    By h123 in forum Qt Programming
    Replies: 8
    Last Post: 15th November 2008, 10:10
  4. QPainter - Retrieve drawText size
    By Raccoon29 in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 09:22
  5. Qt drawText QPainter
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 7th April 2008, 19:00

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.