当前位置: 首页>>代码示例>>C++>>正文


C++ QFontDatabase::families方法代码示例

本文整理汇总了C++中QFontDatabase::families方法的典型用法代码示例。如果您正苦于以下问题:C++ QFontDatabase::families方法的具体用法?C++ QFontDatabase::families怎么用?C++ QFontDatabase::families使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QFontDatabase的用法示例。


在下文中一共展示了QFontDatabase::families方法的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();
}
开发者ID:bogdan-voevoda,项目名称:qt4,代码行数:32,代码来源:main.cpp

示例2: _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;
}
开发者ID:crayonink,项目名称:calligra-2,代码行数:28,代码来源:kfontaction.cpp

示例3: addAppFont

void tst_QFontDatabase::addAppFont()
{
    QFETCH(bool, useMemoryFont);
    QSignalSpy fontDbChangedSpy(QGuiApplication::instance(), SIGNAL(fontDatabaseChanged()));

    QFontDatabase db;

    const QStringList oldFamilies = db.families();
    QVERIFY(!oldFamilies.isEmpty());

    fontDbChangedSpy.clear();

    int id;
    if (useMemoryFont) {
        QFile fontfile("FreeMono.ttf");
        fontfile.open(QIODevice::ReadOnly);
        QByteArray fontdata = fontfile.readAll();
        QVERIFY(!fontdata.isEmpty());
        id = QFontDatabase::addApplicationFontFromData(fontdata);
    } else {
        id = QFontDatabase::addApplicationFont("FreeMono.ttf");
    }
#if defined(Q_OS_HPUX) && defined(QT_NO_FONTCONFIG)
    // Documentation says that X11 systems that don't have fontconfig
    // don't support application fonts.
    QCOMPARE(id, -1);
    return;
#endif
    QCOMPARE(fontDbChangedSpy.count(), 1);
// addApplicationFont is supported on Mac, don't skip the test if it breaks.
#ifndef Q_OS_MAC
    if (id == -1)
        QSKIP("Skip the test since app fonts are not supported on this system");
#endif

    const QStringList addedFamilies = QFontDatabase::applicationFontFamilies(id);
    QVERIFY(!addedFamilies.isEmpty());

    const QStringList newFamilies = db.families();
    QVERIFY(!newFamilies.isEmpty());
    QVERIFY(newFamilies.count() >= oldFamilies.count());

    for (int i = 0; i < addedFamilies.count(); ++i)
        QVERIFY(newFamilies.contains(addedFamilies.at(i)));

    QVERIFY(QFontDatabase::removeApplicationFont(id));
    QCOMPARE(fontDbChangedSpy.count(), 2);

#ifdef Q_OS_MAC
    QEXPECT_FAIL("font file", "QTBUG-23062", Continue);
#endif
    QCOMPARE(db.families(), oldFamilies);
}
开发者ID:SfietKonstantin,项目名称:radeon-qt5-qtbase-kms,代码行数:53,代码来源:tst_qfontdatabase.cpp

示例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;
}
开发者ID:KDE,项目名称:kde-gtk-config,代码行数:28,代码来源:fontshelpers.cpp

示例5: setupTextActions

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())));
}
开发者ID:BackupTheBerlios,项目名称:devqt-svn,代码行数:29,代码来源:devgui.cpp

示例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 );
}
开发者ID:FBergeron,项目名称:tomotko-zaurus,代码行数:7,代码来源:PreferencesDialog.cpp

示例7: renderToPath

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 ));
    }
}
开发者ID:KDE,项目名称:koffice-formulashape,代码行数:25,代码来源:GlyphElement.cpp

示例8: 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);
}
开发者ID:Aconex,项目名称:pcp,代码行数:31,代码来源:settingsdialog.cpp

示例9: initFontFamilyValues

void PreferencesDialog::initFontFamilyValues( QComboBox* comboBox, bool withEmptyEntry /*= false*/ ) const {
    QFontDatabase fontDatabase;
    QStringList families = fontDatabase.families();
    if( withEmptyEntry ) 
        comboBox->addItem( QString( "" ) );
    comboBox->addItems( families );
}
开发者ID:FBergeron,项目名称:tomotko-qt4,代码行数:7,代码来源:PreferencesDialog.cpp

示例10: italicOblique

void tst_QFont::italicOblique()
{
    QFontDatabase fdb;

    QStringList families = fdb.families();
    if (families.isEmpty())
        return;

    QStringList::ConstIterator f_it, f_end = families.end();
    for (f_it = families.begin(); f_it != f_end; ++f_it) {

	QString family = *f_it;
	QStringList styles = fdb.styles(family);
	QVERIFY(!styles.isEmpty());
	QStringList::ConstIterator s_it, s_end = styles.end();
	for (s_it = styles.begin(); s_it != s_end; ++s_it) {
	    QString style = *s_it;

	    if (fdb.isSmoothlyScalable(family, style)) {
		if (style.contains("Oblique")) {
		    style.replace("Oblique", "Italic");
		} else if (style.contains("Italic")) {
		    style.replace("Italic", "Oblique");
		} else {
		    continue;
		}
		QFont f = fdb.font(family, style, 12);
		QVERIFY(f.italic());
	    }
	}
    }
}
开发者ID:SfietKonstantin,项目名称:radeon-qt5-qtbase-kms,代码行数:32,代码来源:tst_qfont.cpp

示例11: 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++;
  }
}
开发者ID:liyulun,项目名称:mantid,代码行数:27,代码来源:ScriptFileInterpreter.cpp

示例12: fillFamiliesList

void ZLQtPaintContext::fillFamiliesList(std::vector<std::string> &families) const {
	bool helveticaFlag = false;
#ifdef USE_ZAURUS_FONTHACK
	std::set<std::string> famSet = ZLZaurusFontHack::families();
	for (std::set<std::string>::const_iterator it = famSet.begin(); it != famSet.end(); ++it) {
		if (*it == HELVETICA) {
			helveticaFlag = true;
		}
		families.push_back(*it);
	}
#else /* USE_ZAURUS_FONTHACK */
	QFontDatabase db;
	QStringList qFamilies = db.families();
	for (QStringList::Iterator it = qFamilies.begin(); it != qFamilies.end(); ++it) {
		std::string family = (*it).ascii();
		if (family == HELVETICA) {
			helveticaFlag = true;
		}
		families.push_back(family);
	}
#endif /* USE_ZAURUS_FONTHACK */
	if (!helveticaFlag) {
		families.push_back(HELVETICA);
	}
}
开发者ID:justsoso8,项目名称:fbreader-0.8.17,代码行数:25,代码来源:ZLQtPaintContext.cpp

示例13:

X11FontDialog::X11FontDialog(QWidget *parent)
    :QDialog( parent)
{
setModal(true);
ui.setupUi(this);
QFontDatabase fdb;
ui.comboBoxFont->addItems( fdb.families() );
}
开发者ID:bpindelski,项目名称:texmaker,代码行数:8,代码来源:x11fontdialog.cpp

示例14: init

void PreferencesBase::init()
{
    setupUi(this);
    QFontDatabase fdb;
    comboFamily->addItems(fdb.families());
    listElements->setCurrentItem( listElements->item(0) );
    currentElement = "";
}
开发者ID:aschet,项目名称:qsaqt5,代码行数:8,代码来源:preferences.cpp

示例15: fillFamiliesList

void ZLQtPaintContext::fillFamiliesList(std::vector<std::string> &families) const {
	QFontDatabase db;
	QStringList qFamilies = db.families();
	for (QStringList::Iterator it = qFamilies.begin(); it != qFamilies.end(); ++it) {
		std::string family = (*it).ascii();
		families.push_back(family);
	}
}
开发者ID:justsoso8,项目名称:fbreader-0.8.17,代码行数:8,代码来源:ZLQtPaintContext.cpp


注:本文中的QFontDatabase::families方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。