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


C++ QFontDatabase类代码示例

本文整理汇总了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();
}
开发者ID:bogdan-voevoda,项目名称:qt4,代码行数:32,代码来源:main.cpp

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

示例3: localizedFonts

void tst_QFontDatabase::localizedFonts()
{
    QFontDatabase db;

    QVERIFY(db.hasFamily(QString::fromUtf8("ヒラギノ明朝 Pro")));
    QVERIFY(!db.hasFamily(QString::fromUtf8("NotValidFont")));
}
开发者ID:PNIDigitalMedia,项目名称:emscripten-qt,代码行数:7,代码来源: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: 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())));
}
开发者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: 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

示例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;
    }
}
开发者ID:RJVB,项目名称:fontweightissue-qt5,代码行数:26,代码来源:dialog.cpp

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

示例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;
    }
  }
开发者ID:Adam-Brown,项目名称:Quantum-GIS,代码行数:27,代码来源:qgsfontutils.cpp

示例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);
}
开发者ID:aaa162,项目名称:focuswriter,代码行数:29,代码来源:theme_dialog.cpp

示例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);
}
开发者ID:danidomi,项目名称:osmc,代码行数:28,代码来源:mainwindow.cpp

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

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

示例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);
    }

}
开发者ID:rodrigoccurvo,项目名称:nixnote2,代码行数:26,代码来源:editorbuttonbar.cpp


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