Qt-interest Archive, July 2007
QPainter::drawText and QFont::setStretch
Message 1 in thread
I'm trying to fit a small text string in a given rectangle.
To get it to fit, I am trying to use QFont::setStretch(), but it has
no effect.
QRect dayBox....
QPainter painter....
QFont foo = painter.font() ;
foo.setPixelSize ( dayBox.height() ) ;
foo.setStretch ( 25 ) ;
int textWidthInPixels = fm.width("00");
if ( textWidthInPixels > ( dayBox.width() )
{
foo.setStretch ( ( 100 * dayBox.width() ) / textWidthInPixels ) ;
}
painter.setFont ( foo ) ;
painter.drawText ( dayBox, Qt::AlignVCenter|Qt::AlignHCenter, "00") ;
Is this a known problem or what ?
--
[ signature omitted ]
Message 2 in thread
Never mind.
I was using 4.2, so I tried 4.3 and the problem went away.
On Jul 6, 2007, at 8:30 PM, Dan White wrote:
> I'm trying to fit a small text string in a given rectangle.
>
> To get it to fit, I am trying to use QFont::setStretch(), but it
> has no effect.
>
>
> QRect dayBox....
>
> QPainter painter....
>
> QFont foo = painter.font() ;
>
> foo.setPixelSize ( dayBox.height() ) ;
>
> int textWidthInPixels = fm.width("00");
>
> if ( textWidthInPixels > ( dayBox.width() )
> {
> foo.setStretch ( ( 100 * dayBox.width() ) /
> textWidthInPixels ) ;
> }
>
> painter.setFont ( foo ) ;
> painter.drawText ( dayBox, Qt::AlignVCenter|Qt::AlignHCenter, "00") ;
>
>
> Is this a known problem or what ?
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]