Font size on WPaintedWidget (Chrome - FireFox - IE)
Added by Rob Van Dyck about 14 years ago
Hi,
I'm new to Wt (and C :-), so I might be doing something stupid. But I'm trying to draw text in a WPaintedWidget in a certain font size. I cannot get it to work on firefox (middle browser in the screenshot). I've tried different methods (see code example), and I've tried setting the 3 preferred rendering methods. Anybody any idea?
I'll include the paint method that I used.
@
// test paint method
void font_test::paintEvent(Wt::WPaintDevice *paintDevice) {
Wt::WPainter painter(paintDevice);
Wt::WFont font10;
Wt::WFont font15;
// draw font size 15
font15.setSize(Wt::WLength(15)); // works in Chrome, IE, not Firefox
//font15.setSize(Wt::WFont::FixedSize, 15); // works in Chrome, IE, not Firefox
//font15.setSize(15); // works in Chrome, IE, not Firefox
painter.setFont(font15);
painter.drawText(10, 10, 20, 20, Wt::WFlagsWt::AlignmentFlag(Wt::AlignMiddle) | Wt::WFlagsWt::AlignmentFlag(Wt::AlignCenter), Wt::TextSingleLine, "10");
// draw font size 10
font10.setSize(Wt::WLength(10));
//font10.setSize(Wt::WFont::FixedSize, 10);
//font10.setSize(10);
painter.setFont(font10);
painter.drawText(10, 30, 20, 20, Wt::WFlagsWt::AlignmentFlag(Wt::AlignMiddle) | Wt::WFlagsWt::AlignmentFlag(Wt::AlignCenter), Wt::TextSingleLine, "10");
}
@
Thanx for any input!
Rob.
Replies (2)
RE: Font size on WPaintedWidget (Chrome - FireFox - IE) - Added by Rob Van Dyck about 14 years ago
Hi,
Is this something that is supposed to work? Ie. has anybody ever had a working version of setting the font size and using WPainter.drawText() on FireFox?
Thanx!
Rob.
RE: Font size on WPaintedWidget (Chrome - FireFox - IE) - Added by Koen Deforche about 14 years ago
Hey Rob,
There seems to be something wrong with how Default family is rendered/interpreted in Firefox.
Specifying a font family solves this, e.g.:
Wt::WFont font10(WFont::SansSerif);
Btw. you can use drawText like this:
painter__.drawText(10, 10, 20, 20, Wt::AlignMiddle | Wt::AlignCenter, Wt::TextSingleLine, "10");
(the WFlags<> are implicit)
Regards,
koen