本文整理汇总了C++中QFontDatabase::styles方法的典型用法代码示例。如果您正苦于以下问题:C++ QFontDatabase::styles方法的具体用法?C++ QFontDatabase::styles怎么用?C++ QFontDatabase::styles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFontDatabase
的用法示例。
在下文中一共展示了QFontDatabase::styles方法的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: 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);
}
示例3: 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;
}
}
示例4: 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());
}
}
}
}
示例5: loadStyles
void BtFontChooserWidget::loadStyles(const QString& font) {
m_styleListWidget->clear();
QFontDatabase database;
Q_FOREACH (const QString &style, database.styles(font)) {
m_styleListWidget->addItem(style);
// This triggers loading the sizes for the first style
restoreListWidgetValue(m_styleListWidget, m_choosenStyle);
}
}
示例6: familySelected
void MainWindow::familySelected(const QString &family)
{
QFontDatabase db;
QStringList styles = db.styles(family);
ui->fontStyleCombo->clear();
ui->fontStyleCombo->addItems(styles);
ui->familySubstitutionCombo->addItem(family);
buildFont();
}
示例7: printFontList
void printFontList()
{
QFontDatabase db;
foreach (const QString &family, db.families()) {
qStdOut() << family << "\n";
foreach (const QString &style, db.styles(family)) {
qStdOut() << "\t" << style << "\n";
}
}
}
示例8:
void
CQFontChooser::
updateStyles()
{
QFontDatabase database;
const QString &family = ncombo_->itemText(ncombo_->currentIndex());
scombo_->clear();
scombo_->addItems(database.styles(family));
}
示例9: fontFamilyHasStyle
bool QgsFontUtils::fontFamilyHasStyle( const QString& family, const QString& style )
{
QFontDatabase fontDB;
if ( !fontFamilyOnSystem( family ) )
return false;
if ( fontDB.styles( family ).contains( style ) )
return true;
#ifdef Q_OS_WIN
QString modified( style );
if ( style == "Roman" )
modified = "Normal";
if ( style == "Oblique" )
modified = "Italic";
if ( style == "Bold Oblique" )
modified = "Bold Italic";
if ( fontDB.styles( family ).contains( modified ) )
return true;
#endif
return false;
}
示例10: metrics
void tst_QFontMetrics::metrics()
{
QFont font;
QFontDatabase fdb;
// Query the QFontDatabase for a specific font, store the
// result in family, style and size.
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) {
const QString &family = *f_it;
QStringList styles = fdb.styles(family);
QStringList::ConstIterator s_it, s_end = styles.end();
for (s_it = styles.begin(); s_it != s_end; ++s_it) {
const QString &style = *s_it;
if (fdb.isSmoothlyScalable(family, style)) {
// smoothly scalable font... don't need to load every pointsize
font = fdb.font(family, style, 12);
QFontMetrics fontmetrics(font);
QCOMPARE(fontmetrics.ascent() + fontmetrics.descent(),
fontmetrics.height());
QCOMPARE(fontmetrics.height() + fontmetrics.leading(),
fontmetrics.lineSpacing());
} else {
QList<int> sizes = fdb.pointSizes(family, style);
QVERIFY(!sizes.isEmpty());
QList<int>::ConstIterator z_it, z_end = sizes.end();
for (z_it = sizes.begin(); z_it != z_end; ++z_it) {
const int size = *z_it;
// Initialize the font, and check if it is an exact match
font = fdb.font(family, style, size);
QFontMetrics fontmetrics(font);
QCOMPARE(fontmetrics.ascent() + fontmetrics.descent(),
fontmetrics.height());
QCOMPARE(fontmetrics.height() + fontmetrics.leading(),
fontmetrics.lineSpacing());
}
}
}
}
}
示例11: styles
void tst_QFontDatabase::styles()
{
QFETCH( QString, font );
QFontDatabase fdb;
QStringList styles = fdb.styles( font );
QStringList::Iterator it = styles.begin();
while ( it != styles.end() ) {
QString style = *it;
QString trimmed = style.trimmed();
++it;
QCOMPARE( style, trimmed );
}
}
示例12:
QList<int> FontSettingsPage::pointSizesForSelectedFont() const
{
QFontDatabase db;
const QString familyName = d_ptr->m_ui->fontComboBox->currentFont().family();
QList<int> sizeLst = db.pointSizes(familyName);
if (!sizeLst.isEmpty())
return sizeLst;
QStringList styles = db.styles(familyName);
if (!styles.isEmpty())
sizeLst = db.pointSizes(familyName, styles.first());
if (sizeLst.isEmpty())
sizeLst = QFontDatabase::standardSizes();
return sizeLst;
}
示例13: loadFontInfo
void DFontChooser::loadFontInfo(const QString &family)
{
QString currentSize = m_fontSize->currentText();
QString currentStyle = m_fontStyle->currentText();
QFontDatabase fdb;
m_fontStyle->clear();
m_fontStyle->addItems(fdb.styles(family));
m_fontSize->clear();
QList<int> points = fdb.pointSizes(family);
foreach(int point, points)
{
m_fontSize->addItem(QString::number(point));
}
示例14: FontBrowserInterface
FontBrowserServer::FontBrowserServer(ProbeInterface *probe, QObject *parent)
: FontBrowserInterface(parent)
, m_selectedFontModel(new FontModel(this))
{
QStandardItemModel *model = new QStandardItemModel(this);
model->setHorizontalHeaderLabels(QStringList() << tr("Fonts") << tr("Smooth sizes"));
QFontDatabase database;
foreach (const QString &family, database.families()) {
QStandardItem *familyItem = new QStandardItem;
familyItem->setText(family);
familyItem->setEditable(false);
familyItem->setData(QFont(family));
foreach (const QString &style, database.styles(family)) {
QStandardItem *styleItem0 = new QStandardItem;
styleItem0->setText(style);
styleItem0->setEditable(false);
styleItem0->setData(database.font(family, style, 10));
QString sizes;
foreach (int points, database.smoothSizes(family, style)) {
sizes += QString::number(points) + ' ';
}
QStandardItem *styleItem1 = new QStandardItem;
styleItem1->setText(sizes.trimmed());
styleItem1->setEditable(false);
styleItem1->setToolTip(sizes.trimmed());
familyItem->appendRow(QList<QStandardItem*>() << styleItem0 << styleItem1);
}
model->appendRow(familyItem);
}
probe->registerModel("com.kdab.GammaRay.FontModel", model);
m_fontSelectionModel = ObjectBroker::selectionModel(model);
connect(m_fontSelectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(updateFonts()));
probe->registerModel("com.kdab.GammaRay.SelectedFontModel", m_selectedFontModel);
}
示例15: testBruteForce
void FontsTest::testBruteForce()
{
QFontDatabase fdb;
QStringList allfamilies = fdb.families();
foreach(const QString& family, allfamilies) {
QStringList styles = fdb.styles(family);
foreach(const QString& style, styles) {
QFont f(family);
f.setStyleName(style);
QString str = fontToString(f);
QFont f2 = stringToFont(str);
QCOMPARE(f2.styleName(), style);
if(str != fontToString(f2)) {
qDebug() << "faulty font:" << str << f << f2;
}
QCOMPARE(fontToString(f2), str);
if(f != f2) {
qDebug() << "faulty font:" << f << f2;
}
// QCOMPARE(f, f2);
}