Menu

#6 auto sizing text object

open
nobody
None
5
2005-01-17
2005-01-17
No

Problem:
You want two adjacent text objects. For instance, text
object 1 would be "super" and text object 2 would be
"karamba" and you want it displayed in your widget as
"superkaramba". The problem is that you don't know what
x,y coordinate to place the second text object at
because you don't know the size of the first text
object (because of user specified fonts and font sizes).

Discussion:
Superkaramba does allow for creating a text object that
automatically sizes itself to accommodate its displayed
text (well, not really):
text_object = createText(widget, 0, 0, 0, 0, "super")
This creates a text object and stores the text
dimensions in TextLabel::textSize (private and not
reachable from the Python API). What *is* reachable
from the Python API is TextLabel::boundingRect which is
set to -1,-1 when a width and height of 0 are specified
in the constructor. Note, the reason why the text is
still shown (in full) even with a boundingRect of -1,-1
is because a Qt::NoClip attribute is given to the text
object.

Possible solutions:
1) Give access to TextLabel::textSize to the Python API.
2) Properly calculate TextLabel::boundingRect for text
objects that are constructed with 0 width and 0 height.

I like solution #2. It seems that the boundingRect can
simply be assigned the value of textSize. I dunno
though, I haven't looked at it too closely to see if
that will mess other things up.

Caveats:
TextLabel::textSize is calculated using QFontMetrics.
For some damn reason on my system, QFontMetrics returns
the wrong information. QFontMetrics::height() and
QFontMetrics::width() return info for fonts 2-4 points
bigger than what I asked for. i.e.: if I ask for the
height of Sans 12, it will give me the height for Sans
14. Whats up with that? Does it have something to do
with my monitor resolution?

Actually, it seems that QFontMetrics returns the
correct sizes for me, its SuperKaramba that is
_displaying_ incorrect fonts. I ask SuperKaramba to
display Sans 12 and it displays Sans 10 (even though
its saying that its displaying Sans 12). I know this
because Sans 12 as displayed by the KDE font chooser
dialog is _much_ bigger than the Sans 12 that
SuperKaramba is writing to my widget.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.