[PyQt] Self-adjusting QTextEdit (PyQt4)
Aaron Digulla
digulla at hepe.com
Sun Apr 27 17:55:47 BST 2008
Wildemar Wildenburger schrieb:
>>> I'm trying to write a notecard application, somewhat in the vein of
>>> Evernote --- basically a succession of little textboxes, one per note,
>>> stacked above one another. To that end I'd like a QTextEdit (or similar)
>>> that adjusts its height (with given width) so that it always shows all
>>> its text, never more, never less.
>>>
>> [. . .]
>> Use QFont to find out what size the font is and then use this as a
>> fixed
>> size for your editors.
>>
> I would have to take into account all the different fonts used, plus
> spaces and margins used by formating and images (it's rich text, after
> all), and add all that up, right?
>
> That seems a little too much trouble to me. I should think that it
> should be fairly easy to find out the vertical size of a stream of text.
> I mean, the scrollbars seem to know . . . do they do all those
> calculations themselves? I would expect them to simply ask the text
> component "Hey, how tall are you?".
I'm not sure if the API exposes the internal widgets but the text
content is of course just a simple widget of which you can only see a
small part. The QTextEdit just builds itself from these parts (text
editor, scroll bars and a nice frame to wrap those three together).
Check the slots of the scroll bars to see how they get the visible/total
size of the scrolled area. These should be the number you're looking for.
Regards,
--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://darkviews.blogspot.com/ http://www.pdark.de/
More information about the PyQt
mailing list