#3 ToolTip text getting top cut off

open
nobody
None
5
2004-09-19
2004-09-19
Anonymous
No

The ToolTipWin is too small vertically... by default it
is the fontSize. This causes the surrounding black
shadow of the text to get the top chopped off.

Solution: Make ToolTipWin a bit larger vertically, say
10 pixels. Then, render the font 5 pixels lower. This
gives 5 pixels on top and on bottom to render the text
shadow.

Changes marked with //JDS

file: tooltip.cpp

void ToolTip::doUpdateGeometry() {
QFontMetrics *metrics = new QFontMetrics(font);
w = metrics->width(text);
w = w + 5; // 5 pixels more
h = metrics->height() + 10; //JDS

resize(w,h);
update();
}

void ToolTip::paintEvent(QPaintEvent *)
{
QPixmap pm(size());
QBitmap bm(size());

// draw the mask bitmap

QPainter p0;
p0.begin(&bm);

p0.fillRect(rect(), Qt::color0);

p0.setPen( Qt::color1 );
p0.setFont(font);

for (int i = -2; i <= 2; i++)
for (int j = -2; j <= 2; j++) {
p0.drawText(1 + i, fontSize + j + 5,
text); //JDS
}

p0.drawText(1, fontSize + 5, text); // JDS

p0.end();

// draw the buffer pixmap

QPainter p;
p.begin(&pm);

p.setPen( bgColor );
p.setFont(font);

for (int i = -2; i <= 2; i++)
for (int j = -2; j <= 2; j++) {
p.drawText(1 + i, fontSize + j + 5,
text); //JDS
}
// now, draw normal text
p.setPen( fontColor );
p.setFont(font);
p.drawText(1, fontSize + 5, text); //JDS

p.end();

// update the widget

bitBlt(this, 0, 0, &pm);
info->setState(NETWinInfo::SkipTaskbar |
NETWinInfo::SkipPager, NETWinIn
fo::SkipTaskbar | NETWinInfo::SkipPager);
setMask(bm); // for transparency
}

Discussion