The Debian KDE solution: The KGlobalSettings KDE object contains static members returning the needed QFonts:
QFont KGlobalSettings
::generalFont() const;
// the general proportional font QFont KGlobalSettings
::fixedFont() const;
// the fixed pitch font QFont KGlobalSettings
::toolbarFont() const;
// the toolbar font QFont KGlobalSettings
::menuFont() const;
// the menu font QFont KGlobalSettings
::windowTitleFont() const;
// the titlebar font QFont KGlobalSettings
::largeFont() const;
// the 48 pts font QFont KGlobalSettings
::smallestReadableFont() const;
// the smallest readable font
QFont KGlobalSettings::generalFont() const; // the general proportional font
QFont KGlobalSettings::fixedFont() const; // the fixed pitch font
QFont KGlobalSettings::toolbarFont() const; // the toolbar font
QFont KGlobalSettings::menuFont() const; // the menu font
QFont KGlobalSettings::windowTitleFont() const; // the titlebar font
QFont KGlobalSettings::largeFont() const; // the 48 pts font
QFont KGlobalSettings::smallestReadableFont() const; // the smallest readable font
To copy to clipboard, switch view to plain text mode
Add the libkdeui library to the .pro file (I have noticed that the library is kdeui on Ubuntu). My current font setting procedure:
#include <kglobalsettings.h>
#include <text.hpp>
bool Text::FontConf( const fontconf_t& fc ) // Text is "public QPlainTextEdit"
{
QColor co
(currfmt.
foreground().
color());
// currfmt is QTextCharFormat of the current text char format int fs = currfmt.font().pointSize();
bool bo
= (currfmt.
fontWeight() == QFont::Bold);
bool bb = false;
if( currfmt.fontFixedPitch() != fc.isfixed )
{
currfmt.setFont(fc.isfixed ? KGlobalSettings::fixedFont() : KGlobalSettings::generalFont());
currfmt.setFontFixedPitch(fc.isfixed);
bb = true;
}
if( fs != fc.psize )
{
currfmt.font().setPointSize(fc.psize);
bb = true;
}
if( bo != fc.isbold )
{
currfmt.
setFontWeight(fc.
isbold ?
QFont::Bold : QFont::Normal);
bb = true;
}
if( currfmt.fontItalic() != fc.isitalic )
{
currfmt.setFontItalic(fc.isitalic);
bb = true;
}
if( co != fc.color )
{
currfmt.setForeground(newcolor);
bb = true;
}
if( bb ) setCurrentCharFormat(currfmt);
return bb;
}
#include <kglobalsettings.h>
#include <text.hpp>
bool Text::FontConf( const fontconf_t& fc ) // Text is "public QPlainTextEdit"
{
QColor co(currfmt.foreground().color()); // currfmt is QTextCharFormat of the current text char format
int fs = currfmt.font().pointSize();
bool bo = (currfmt.fontWeight() == QFont::Bold);
bool bb = false;
if( currfmt.fontFixedPitch() != fc.isfixed )
{
currfmt.setFont(fc.isfixed ? KGlobalSettings::fixedFont() : KGlobalSettings::generalFont());
currfmt.setFontFixedPitch(fc.isfixed);
bb = true;
}
if( fs != fc.psize )
{
currfmt.font().setPointSize(fc.psize);
bb = true;
}
if( bo != fc.isbold )
{
currfmt.setFontWeight(fc.isbold ? QFont::Bold : QFont::Normal);
bb = true;
}
if( currfmt.fontItalic() != fc.isitalic )
{
currfmt.setFontItalic(fc.isitalic);
bb = true;
}
if( co != fc.color )
{
QBrush newcolor(fc.color);
currfmt.setForeground(newcolor);
bb = true;
}
if( bb ) setCurrentCharFormat(currfmt);
return bb;
}
To copy to clipboard, switch view to plain text mode
It works in simple tests on fixed font. Possible minor problems ahead: what all is reset by setFont()? In the other words, what all do I need to set unconditionally in FontConf() after setFont() (point size, bold/italic, etc.)? Note: the FontFixedPitch() seems to be only a flag unrelated to the font. If I set a fixed font, the flag returned by FontFixedPitch() does not change. Therefore, setFontFixedPitch() along with the font to keep consistency.
Bookmarks