On 09/10/2018 11:04 AM, Thiago Macieira
wrote:
Sorry to necro-post here, but, I have wanted to comment on this for a while. Choosing fonts can be a real PITA, especially when you need a readable fixed width font for reports. Here is a code snippet I have in my xpnsqt2 project. Had to hack it again this year to remove binary.On Saturday, 8 September 2018 11:56:45 PDT Tomasz Olszak wrote:So as well you can to it in runtime and don't need macro.Better yet, don't do anything. Use the font that the user configured and don't override. If you don't like the font, use your desktop's font changing tool to make the customisation. QString ReportBrowserDialog::chooseFixedFont() { // TODO:: change this to user dialog with font pick list. // // Cannot assume every system will have Courier 10 Pitch installed // There could be a lot of funky fixed width symbol fonts // Do our best to find a fixed width font which isn't weird. QFontDatabase fontdb; int font_sub = -1; int fixed_pitch_count = 0; QStringList fontFamilies = fontdb.families(); for (int x=0; x < fontFamilies.size() && font_sub < 0; x++) { qDebug() << "Font: " << fontFamilies[x]; if (fontFamilies[x].contains("Courier")) { font_sub = x; } else { if (!fontFamilies[x].contains("Binary") && !fontFamilies[x].contains("Symbol") && !fontFamilies[x].contains("Clock")) if (fontdb.isFixedPitch(fontFamilies[x])) { qDebug() << "Fixed width font: " << fontFamilies[x]; fixed_pitch_count++; if (fixed_pitch_count > 3) if (font_sub < 0) font_sub = x; } } } return (fontFamilies[font_sub]); } At some point I need to change this to a font selection dialog, but, haven't had time. What's the count > 3 hack? There are usually 3 garbage fixed width fonts installed on YABU releases which sort to the top of the list. When I built and ran this on PingyOS earlier this year I had to add "Binary" and I think "Clock" to the exclusion list. Even though Courier is not technically a fixed width font, it makes the report work. You can find a screen shot of the browser here: http://www.logikalsolutions.com/wordpress/wp-content/uploads/2018/09/ReportBrowser_047.png -- Roland Hughes, President Logikal Solutions (630) 205-1593 http://www.theminimumyouneedtoknow.com http://www.infiniteexposure.net http://www.johnsmith-book.com http://www.logikalblog.com http://www.interestingauthors.com/blog http://lesedi.us |
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest