Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, October 2007
RE: Counting lines with QFontMetrics::width()


Message 1 in thread

Dmitry Teslenko wrote:
> Problem is algorithm sometimes produces fewer lines than actually
> drawn. I.e. length of the words is actually bigger than sum of
> QFontMetrics::width() of all chars of the word.

I think the problem is with your algorithm, you are doing the
word-breaks too late (when you're going to the next line, your last line
is alread too long!)

Why don't you use Qt's word breaking algorithm?

http://doc.trolltech.com/4.3/qfontmetrics.html#boundingRect-6

If you specify a bounding rect with your desired width and unlimited
height, this should do what you want without all the hassle (and bugs)
of doing it all by yourself.

Cheers,
Peter

--
 [ signature omitted ] 

Message 2 in thread

On 01/10/2007, Peter Prade <prade@xxxxxxxxxxx> wrote:
> I think the problem is with your algorithm, you are doing the
> word-breaks too late (when you're going to the next line, your last line
> is alread too long!)
>
> Why don't you use Qt's word breaking algorithm?
>
> http://doc.trolltech.com/4.3/qfontmetrics.html#boundingRect-6

Thanks! Truly there were errors but I've fixed some and now it works
so-so. I'm to use Qt3 and there's no acess to such method. Thanks
anyway!

--
 [ signature omitted ] 

Message 3 in thread

http://doc.trolltech.com/3.3/qfontmetrics.html#boundingRect-3

looks fine to me.

Cheers,
Peter

P.S.:
You should state it in the subject when you're asking about Qt3.

> -----Ursprüngliche Nachricht-----
> Von: Dmitry Teslenko [mailto:dteslenko@xxxxxxxxx] 
> Gesendet: Dienstag, 2. Oktober 2007 16:23
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: Re: Counting lines with QFontMetrics::width()
> 
> On 01/10/2007, Peter Prade <prade@xxxxxxxxxxx> wrote:
> > I think the problem is with your algorithm, you are doing the 
> > word-breaks too late (when you're going to the next line, your last 
> > line is alread too long!)
> >
> > Why don't you use Qt's word breaking algorithm?
> >
> > http://doc.trolltech.com/4.3/qfontmetrics.html#boundingRect-6
> 
> Thanks! Truly there were errors but I've fixed some and now 
> it works so-so. I'm to use Qt3 and there's no acess to such 
> method. Thanks anyway!
> 
> --
> 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 ]