本文整理汇总了C++中QFontDatabase类的典型用法代码示例。如果您正苦于以下问题:C++ QFontDatabase类的具体用法?C++ QFontDatabase怎么用?C++ QFontDatabase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QFontDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
QApplication app(argc, argv);
//! [0]
QFontDatabase database;
QTreeWidget fontTree;
fontTree.setColumnCount(2);
fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes");
foreach (const QString &family, database.families()) {
QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree);
familyItem->setText(0, family);
foreach (const QString &style, database.styles(family)) {
QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem);
styleItem->setText(0, style);
QString sizes;
foreach (int points, database.smoothSizes(family, style))
sizes += QString::number(points) + " ";
styleItem->setText(1, sizes.trimmed());
}
//! [0] //! [1]
}
//! [1]
fontTree.resizeColumnToContents(0);
fontTree.show();
return app.exec();
}
示例2: Q_UNUSED
QRectF GlyphElement::renderToPath( const QString& raw, QPainterPath& path ) const
{
Q_UNUSED( raw )
Q_UNUSED( path )
// try to lookup the char in the font database
AttributeManager am;
QString fontFamily = am.stringOf( "fontfamily", this );
QFontDatabase db;
QFont tmpFont;
// determine if the specified font and glyph can be found
if( db.families().contains( fontFamily ) )
{
tmpFont.setFamily( fontFamily );
path.addText( path.currentPosition(), tmpFont,
QChar( am.stringOf( "index", this ).toInt() ) );
QFontMetricsF fm(tmpFont);
return fm.boundingRect(QChar( am.stringOf( "index", this ).toInt() ) );
}
else { // if not found use alt text
path.addText( path.currentPosition(), font(), am.stringOf( "alt", this ) );
QFontMetricsF fm(font());
return fm.boundingRect(am.stringOf( "alt", this ));
}
}
示例3: localizedFonts
void tst_QFontDatabase::localizedFonts()
{
QFontDatabase db;
QVERIFY(db.hasFamily(QString::fromUtf8("ヒラギノ明朝 Pro")));
QVERIFY(!db.hasFamily(QString::fromUtf8("NotValidFont")));
}
示例4: stringToFont
QFont stringToFont(const QString& font)
{
QFontDatabase fdb;
QString fontFamily;
int familyIdx=-1;
QStringList allFamilies = fdb.families();
for(int idx=font.indexOf(' '); idx<font.size() && idx>=0; idx=font.indexOf(' ', idx+1)) {
QString testFont = font.left(idx);
if(allFamilies.contains(testFont)) {
fontFamily = testFont;
familyIdx = idx;
}
}
QFont f;
f.setFamily(fontFamily);
QRegularExpression fontRx(QStringLiteral(" (.*) +([0-9]+)$"));
QRegularExpressionMatch match = fontRx.match(font, familyIdx);
if (match.isValid()) {
QString fontStyle = match.captured(1).trimmed();
int fontSize = match.captured(2).toInt();
f.setStyleName(fontStyle);
f.setPointSize(fontSize);
} else {
qWarning() << "Couldn't figure out syle and size" << font;
}
return f;
}
示例5: QToolBar
void DevGUI::setupTextActions()
{
QToolBar *tb = new QToolBar(this);
tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
tb->setWindowTitle(tr("Format Actions"));
addToolBarBreak(Qt::TopToolBarArea);
addToolBar(tb);
Font = new QComboBox(tb);
tb->addWidget(Font);
Font->setEditable(true);
QFontDatabase db;
Font->addItems(db.families());
connect(Font, SIGNAL(activated(const QString &)),
this, SLOT(textFamily(const QString &)));
Font->setCurrentIndex(Font->findText(DevApp::font().family()));
Size = new QComboBox(tb);
Size->setObjectName("Size");
tb->addWidget(Size);
Size->setEditable(true);
foreach(int size, db.standardSizes())
Size->addItem(QString::number(size));
connect(Size, SIGNAL(activated(const QString &)),
this, SLOT(textSize(const QString &)));
Size->setCurrentIndex(Size->findText(QString::number(DevApp::font().pointSize())));
}
示例6: initFontFamilyValues
void PreferencesDialog::initFontFamilyValues( QComboBox* comboBox, bool withEmptyEntry = false ) const {
QFontDatabase fontDatabase;
QStringList families = fontDatabase.families( false );
if( withEmptyEntry )
comboBox->insertItem( QString::null );
comboBox->insertStringList( families );
}
示例7: setFont
/// Set a font
void ScriptFileInterpreter::setFont(const QString &fontFamily) {
// This needs to check if the font exists and use default if not
QFontDatabase database;
// Select saved choice. If not available, use current font
QString fontToUse = m_editor->lexer()->defaultFont().family();
if (database.families().contains(fontFamily))
fontToUse = fontFamily;
QFont defaultFont = m_editor->lexer()->defaultFont();
defaultFont.setFamily(fontToUse);
m_editor->lexer()->setDefaultFont(defaultFont);
// Check through all styles until it starts creating new ones (they match the
// default style)
// On each, copy the font and change only the family
int count = 0;
while (m_editor->lexer()->font(count) != m_editor->lexer()->defaultFont()) {
QFont font = m_editor->lexer()->font(count);
font.setFamily(fontToUse);
m_editor->lexer()->setFont(font, count);
count++;
}
}
示例8: stripStyleName
QFont stripStyleName(QFont &f, QFontDatabase &db)
{
const QString &styleName = f.styleName();
if (styleName.isEmpty()) {
return f;
} else {
QFont g = (db.styleString(f) != styleName) ?
db.font(f.family(), styleName, f.pointSize())
: QFont(f.family(), f.pointSize(), f.weight());
if (auto s = f.pixelSize() > 0) {
g.setPixelSize(s);
}
g.setStyleHint(f.styleHint(), f.styleStrategy());
g.setStyle(f.style());
if (f.underline()) {
g.setUnderline(true);
}
if (f.strikeOut()) {
g.setStrikeOut(true);
}
if (f.fixedPitch()) {
g.setFixedPitch(true);
}
return g;
}
}
示例9: setupFontLists
void SettingsDialog::setupFontLists()
{
QFontDatabase database;
const QStringList families = database.families();
console->post(PmChart::DebugUi,
"SettingsDialog::setupFontLists: default %s [%d]",
PmChart::defaultFontFamily(),
PmChart::defaultFontSize());
QCompleter *completeFamily = new QCompleter(families, familyLineEdit);
familyLineEdit->setCompleter(completeFamily);
familyListWidget->insertItems(0, families);
QString family = globalSettings.fontFamily;
familyLineEdit->setText(family);
updateFontList(familyListWidget, family);
styleListWidget->insertItems(0, database.styles(family));
QString style = globalSettings.fontStyle;
styleLineEdit->setText(style);
updateFontList(styleListWidget, style);
QStringList sizes;
foreach (int points, database.smoothSizes(family, style))
sizes << QString::number(points);
sizeListWidget->insertItems(0, sizes);
QString size = QString::number(globalSettings.fontSize);
sizeLineEdit->setText(size);
updateFontList(sizeListWidget, size);
}
示例10: updateFontViaStyle
bool QgsFontUtils::updateFontViaStyle( QFont& f, const QString& fontstyle, bool fallback )
{
if ( fontstyle.isEmpty() )
{
return false;
}
QFontDatabase fontDB;
if ( !fallback )
{
// does the font even have the requested style?
bool hasstyle = false;
foreach ( const QString &style, fontDB.styles( f.family() ) )
{
if ( style == fontstyle )
{
hasstyle = true;
break;
}
}
if ( !hasstyle )
{
return false;
}
}
示例11: fontChanged
void ThemeDialog::fontChanged()
{
QFontDatabase db;
QFont font = m_font_names->currentFont();
QList<int> font_sizes = db.smoothSizes(font.family(), QString());
if (font_sizes.isEmpty()) {
font_sizes = db.standardSizes();
}
qreal font_size = m_font_sizes->currentText().toDouble();
if (font_size < 0.1) {
font_size = std::lround(m_theme.textFont().pointSizeF() * 10.0) * 0.1;
}
m_font_sizes->blockSignals(true);
m_font_sizes->clear();
int index = 0;
for (int i = 0; i < font_sizes.count(); ++i) {
int size = font_sizes.at(i);
if (size <= font_size) {
index = i;
}
m_font_sizes->addItem(QString::number(size));
}
m_font_sizes->setCurrentIndex(index);
m_font_sizes->setEditText(QString::number(font_size));
m_font_sizes->setValidator(new QDoubleValidator(font_sizes.first(), font_sizes.last(), 1, m_font_sizes));
m_font_sizes->blockSignals(false);
}
示例12: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow), device(NULL), preseed(NULL)
{
ui->setupUi(this);
/* Set up logging */
logger = new Logger();
logger->addLine("Starting OSMC installer");
/* UI set up */
#ifdef Q_WS_QWS
QWSServer *server = QWSServer::instance();
if(server)
{
server->setCursorVisible(false);
server->setBackground(QBrush(Qt::black));
this->setWindowFlags(Qt::Tool|Qt::CustomizeWindowHint);
}
#endif
this->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, this->size(), qApp->desktop()->availableGeometry()));
QFontDatabase fontDatabase;
fontDatabase.addApplicationFont(":/assets/resources/SourceSansPro-Regular.ttf");
/* Populate target list map */
targetList = new TargetList();
utils = new Utils(logger);
}
示例13: initFontFamilyValues
void PreferencesDialog::initFontFamilyValues( QComboBox* comboBox, bool withEmptyEntry /*= false*/ ) const {
QFontDatabase fontDatabase;
QStringList families = fontDatabase.families();
if( withEmptyEntry )
comboBox->addItem( QString( "" ) );
comboBox->addItems( families );
}
示例14: _k_fontList
QStringList _k_fontList(const QFontComboBox::FontFilters &fontFilters = QFontComboBox::AllFonts)
{
QFontDatabase dbase;
QStringList families;
if (fontFilters == QFontComboBox::AllFonts) {
families = dbase.families();
} else {
const QFontComboBox::FontFilters scalableMask = (QFontComboBox::ScalableFonts | QFontComboBox::NonScalableFonts);
const QFontComboBox::FontFilters spacingMask = (QFontComboBox::ProportionalFonts | QFontComboBox::MonospacedFonts);
foreach (const QString &family, dbase.families()) {
if ((fontFilters & scalableMask) && (fontFilters & scalableMask) != scalableMask) {
if (bool(fontFilters & QFontComboBox::ScalableFonts) != dbase.isSmoothlyScalable(family))
continue;
}
if ((fontFilters & spacingMask) && (fontFilters & spacingMask) != spacingMask) {
if (bool(fontFilters & QFontComboBox::MonospacedFonts) != dbase.isFixedPitch(family))
continue;
}
families << family;
}
}
families.sort();
return families;
}
示例15: loadFontSizeComboBox
// Load the list of font sizes
void EditorButtonBar::loadFontSizeComboBox(QString name) {
QFontDatabase fdb;
fontSizes->clear();
QList<int> sizes = fdb.smoothSizes(name, "Normal");
for (int i=0; i<sizes.size(); i++) {
fontSizes->addItem(QString::number(sizes[i]), sizes[i]);
}
if (sizes.size() == 0) {
fontSizes->addItem("8", 8);
fontSizes->addItem("9", 9);
fontSizes->addItem("10", 10);
fontSizes->addItem("11", 11);
fontSizes->addItem("12", 12);
fontSizes->addItem("14", 14);
fontSizes->addItem("15", 15);
fontSizes->addItem("16", 16);
fontSizes->addItem("17", 17);
fontSizes->addItem("18", 18);
fontSizes->addItem("19", 19);
fontSizes->addItem("20", 20);
fontSizes->addItem("21", 21);
fontSizes->addItem("22", 22);
}
}