本文整理汇总了C++中QFontDatabase::styleString方法的典型用法代码示例。如果您正苦于以下问题:C++ QFontDatabase::styleString方法的具体用法?C++ QFontDatabase::styleString怎么用?C++ QFontDatabase::styleString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFontDatabase
的用法示例。
在下文中一共展示了QFontDatabase::styleString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Font::update( QPaintDeviceMetrics* devMetrics ) const
{
f.setFamily( fontDef.family.isEmpty() ? KHTMLFactory::defaultHTMLSettings()->stdFontName() : fontDef.family );
f.setItalic( fontDef.italic );
f.setWeight( fontDef.weight );
QFontDatabase db;
int size = fontDef.size;
int lDpiY = kMax(devMetrics->logicalDpiY(), 96);
// ok, now some magic to get a nice unscaled font
// all other font properties should be set before this one!!!!
if( !db.isSmoothlyScalable(f.family(), db.styleString(f)) )
{
QValueList<int> pointSizes = db.smoothSizes(f.family(), db.styleString(f));
// lets see if we find a nice looking font, which is not too far away
// from the requested one.
// kdDebug(6080) << "khtml::setFontSize family = " << f.family() << " size requested=" << size << endl;
QValueList<int>::Iterator it;
float diff = 1; // ### 100% deviation
float bestSize = 0;
for( it = pointSizes.begin(); it != pointSizes.end(); ++it )
{
float newDiff = ((*it)*(lDpiY/72.) - float(size))/float(size);
//kdDebug( 6080 ) << "smooth font size: " << *it << " diff=" << newDiff << endl;
if(newDiff < 0) newDiff = -newDiff;
if(newDiff < diff)
{
diff = newDiff;
bestSize = *it;
}
}
//kdDebug( 6080 ) << "best smooth font size: " << bestSize << " diff=" << diff << endl;
if ( bestSize != 0 && diff < 0.2 ) // 20% deviation, otherwise we use a scaled font...
size = (int)((bestSize*lDpiY) / 72);
}
// make sure we don't bust up X11
size = KMAX(0, KMIN(255, size));
// qDebug("setting font to %s, italic=%d, weight=%d, size=%d", fontDef.family.latin1(), fontDef.italic,
// fontDef.weight, size );
f.setPixelSize( size );
fm = QFontMetrics( f );
fontDef.hasNbsp = fm.inFont( 0xa0 );
}
示例2: 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;
}
}
示例3: arg
void
CQFontChooser::
updateWidgets()
{
cedit_ ->setVisible(style_ == FontEdit );
cbutton_->setVisible(style_ == FontButton);
clabel_ ->setVisible(style_ == FontLabel || style_ == FontDetailLabel);
button_ ->setVisible(style_ != FontCombo );
ncombo_ ->setVisible(style_ == FontCombo );
scombo_ ->setVisible(style_ == FontCombo );
zcombo_ ->setVisible(style_ == FontCombo );
if (fixedWidth_)
ncombo_->setFontFilters(QFontComboBox::MonospacedFonts);
else
ncombo_->setFontFilters(QFontComboBox::AllFonts);
ncombo_->setWritingSystem(QFontDatabase::Latin);
//ncombo_->setCurrentIndex(1);
cedit_->setText(fontName_);
cbutton_->setFont(font_);
cbutton_->setText(exampleText());
clabel_->setFont(font_);
if (style_ == FontDetailLabel) {
QFontDatabase database;
QString style = database.styleString(font_);
clabel_->setText(QString("%1, %2, %3").
arg(font_.substitute(font_.family())).arg(style).arg(font_.pointSize()));
}
else
clabel_->setText(exampleText());
int nind = ncombo_->findText(font_.family());
if (nind >= 0)
ncombo_->setCurrentIndex(nind);
updateStyles();
updateSizes ();
updateCombos();
layout()->invalidate();
}
示例4:
void
CQFontChooser::
updateCombos()
{
QFontDatabase database;
QString style = database.styleString(font_);
int sind = scombo_->findText(style);
if (sind == -1) {
bool italic = (style == "Italic" || style == "Bold Italic");
if (italic) {
if (style == "Italic" ) style = "Oblique";
if (style == "Bold Italic") style = "Bold Oblique";
sind = scombo_->findText(style);
if (sind == -1) {
if (style == "Bold Oblique") style = "Oblique";
sind = scombo_->findText(style);
}
if (sind == -1) {
if (style == "Oblique") style = "Italic";
sind = scombo_->findText(style);
}
}
}
if (sind >= 0)
scombo_->setCurrentIndex(sind);
int zind = zcombo_->findText(QString("%1").arg(font_.pointSize()));
if (zind >= 0)
zcombo_->setCurrentIndex(zind);
}
示例5: setFont
void BtFontChooserWidget::setFont(const QFont& font) {
disconnect(m_fontListWidget, nullptr, nullptr, nullptr);
disconnect(m_styleListWidget, nullptr, nullptr, nullptr);
disconnect(m_sizeListWidget, nullptr, nullptr, nullptr);
// set the font
m_font = font;
const QString fontFamily = font.family();
restoreListWidgetValue(m_fontListWidget, fontFamily);
// set the style
loadStyles(fontFamily);
QFontDatabase database;
const QString styleString = database.styleString(m_font);
m_choosenStyle = styleString;
restoreListWidgetValue(m_styleListWidget, styleString);
// set the size
loadSizes(fontFamily, styleString);
restoreListWidgetValue(m_sizeListWidget, QString::number(m_font.pointSize()) );
outputHtmlText();
connectListWidgets();
}
示例6: 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 = fontFamilyHasStyle( f.family(), fontstyle );
if ( !hasstyle )
{
return false;
}
}
// is the font's style already the same as requested?
if ( fontstyle == fontDB.styleString( f ) )
{
return false;
}
QFont appfont = QApplication::font();
int defaultSize = appfont.pointSize(); // QFontDatabase::font() needs an integer for size
QFont styledfont;
bool foundmatch = false;
// if fontDB.font() fails, it returns the default app font; but, that may be the target style
styledfont = fontDB.font( f.family(), fontstyle, defaultSize );
if ( appfont != styledfont || fontstyle != fontDB.styleString( f ) )
{
foundmatch = true;
}
// default to first found style if requested style is unavailable
// this helps in the situations where the passed-in font has to have a named style applied
if ( fallback && !foundmatch )
{
QFont testFont = QFont( f );
testFont.setPointSize( defaultSize );
// prefer a style that mostly matches the passed-in font
Q_FOREACH ( const QString &style, fontDB.styles( f.family() ) )
{
styledfont = fontDB.font( f.family(), style, defaultSize );
styledfont = styledfont.resolve( f );
if ( testFont.toString() == styledfont.toString() )
{
foundmatch = true;
break;
}
}
// fallback to first style found that works
if ( !foundmatch )
{
Q_FOREACH ( const QString &style, fontDB.styles( f.family() ) )
{
styledfont = fontDB.font( f.family(), style, defaultSize );
if ( QApplication::font() != styledfont )
{
foundmatch = true;
break;
}
}
}
示例7: QDialog
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
setAttribute(Qt::WA_QuitOnClose, true);
qApp->setStyleSheet("QLabel{ background: white }");
int frameStyle = QFrame::Sunken | QFrame::Panel;
QSettings store;
QVariant prefStoreType = store.value("storeNativeQFont");
if (prefStoreType != QVariant()) {
storeNativeQFont = prefStoreType.toBool();
}
else{
storeNativeQFont = true;
}
QVariant prefFont = store.value("font");
fontLabel = new QLabel;
fontLabel->setFrameStyle(frameStyle);
fontLabel->setToolTip(tr("this shows what QFont::key() returns for the current font"));
font = fontLabel->font();
if (prefFont != QVariant()) {
if (storeNativeQFont) {
if (prefFont.canConvert<QFont>()) {
font = prefFont.value<QFont>();
qWarning() << "Restoring saved native font" << font << "from" << prefFont;
fontDetails(font, stdout);
}
else {
qWarning() << "Cannot restore font from" << prefFont;
}
}
else {
QFont fn;
if (!fn.fromString(prefFont.toString())) {
qWarning() << "Failed to restore font from" << prefFont << "toString=" << prefFont.toString();
}
else {
qWarning() << "Restoring saved font" << fn;
fontDetails(fn, stdout);
font = fn;
}
}
}
fontLabel->setFont(font);
fontLabel->setText(font.key());
QPushButton *fontButton = new QPushButton(tr("QFontDialog::get&Font()"));
fontButton->setToolTip(tr("this initialises the getFont dialog with the font object selected previously"));
fontLabel2 = new QLabel;
fontLabel2->setFrameStyle(frameStyle);
fontLabel2->setToolTip(tr("this shows the current font's common attributes"));
fontLabel2->setFont(font);
fontLabel2->setText(fontRepr(font));
QPushButton *fontButton2 = new QPushButton(tr("QFontDialog::getFont(font.key())"));
fontButton2->setToolTip(tr("this initialises the getFont dialog with the shown representation of previously selected font"));
connect(fontButton, SIGNAL(clicked()), this, SLOT(setFont()));
connect(fontButton2, SIGNAL(clicked()), this, SLOT(setFontFromSpecs()));
fontPreview = new QLabel;
fontPreview->setFrameStyle(frameStyle);
fontPreview->setToolTip(tr("this shows current font family, QFont::styleString() and decimal point size"));
fontPreview->setFont(font);
QFontDatabase db;
fontPreview->setText( font.family() + tr(" ") + db.styleString(font) + tr(" @ ") + QString("%1pt").arg(font.pointSizeF()) );
clonedFontPreview = new QLabel;
clonedFontPreview->setFrameStyle(frameStyle);
clonedFontPreview->setToolTip(tr("this shows the font cloned without styleName"));
clonedBoldFontPreview = new QLabel;
clonedBoldFontPreview->setFrameStyle(frameStyle);
clonedBoldFontPreview->setToolTip(tr("this shows the font cloned without styleName and made bold"));
{ QFontDatabase db;
QFont tmp = stripStyleName(font, db);
clonedFontPreview->setFont(tmp);
tmp.setBold(true);
clonedBoldFontPreview->setFont(tmp);
}
clonedFontPreview->setText(clonedFontPreview->font().key());
clonedBoldFontPreview->setText(clonedBoldFontPreview->font().key());
QPushButton *styleButton = new QPushButton(tr("set styleName"));
styledFontPreview = new QLabel;
styledFontPreview->setFrameStyle(frameStyle);
#define STYLEDFNTPREVIEWTT "this shows the result of setting a stylename on the selected font\nResolves to: %1"
styledFontPreview->setToolTip(tr(STYLEDFNTPREVIEWTT).arg(styledFontPreview->font().toString()));
connect(styleButton, SIGNAL(clicked()), this, SLOT(setFontStyleName()));
QPushButton *famButton = new QPushButton(tr("Lookup from Family"));
fontFamilyPreview = new QLabel;
fontFamilyPreview->setFrameStyle(frameStyle);
connect(famButton, SIGNAL(clicked()), this, SLOT(getFontFromFamily()));
fontStyleName = new QLabel;
fontStyleName->setFrameStyle(frameStyle);
fontStyleName->setToolTip(tr("this shows the current styleName attribute that has been set on the font"));
QGridLayout *layout = new QGridLayout;
const QString doNotUseNativeDialog = tr("Do not use native dialog");
//.........这里部分代码省略.........
示例8: settings
//.........这里部分代码省略.........
ui->toolTipEffectCombo->setCurrentIndex(2);
else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip))
ui->toolTipEffectCombo->setCurrentIndex(1);
if (QApplication::isEffectEnabled(Qt::UI_AnimateToolBox))
ui->toolBoxEffectCombo->setCurrentIndex(1);
QSize globalStrut = QApplication::globalStrut();
ui->strutWidthSpinBox->setValue(globalStrut.width());
ui->strutHeightSpinBox->setValue(globalStrut.height());
// find the default family
QStringList::Iterator sit = families.begin();
int i = 0, possible = -1;
while (sit != families.end()) {
if (*sit == QApplication::font().family())
break;
if ((*sit).contains(QApplication::font().family()))
possible = i;
i++;
sit++;
}
if (sit == families.end())
i = possible;
if (i == -1) // no clue about the current font
i = 0;
ui->fontFamilyCombo->setCurrentIndex(i);
QStringList styles = db.styles(ui->fontFamilyCombo->currentText());
ui->fontStyleCombo->addItems(styles);
QString stylestring = db.styleString(QApplication::font());
sit = styles.begin();
i = 0;
possible = -1;
while (sit != styles.end()) {
if (*sit == stylestring)
break;
if ((*sit).contains(stylestring))
possible = i;
i++;
sit++;
}
if (sit == styles.end())
i = possible;
if (i == -1) // no clue about the current font
i = 0;
ui->fontStyleCombo->setCurrentIndex(i);
i = 0;
for (int psize = QApplication::font().pointSize(); i < ui->pointSizeCombo->count(); ++i) {
const int sz = ui->pointSizeCombo->itemText(i).toInt();
if (sz == psize) {
ui->pointSizeCombo->setCurrentIndex(i);
break;
} else if(sz > psize) {
ui->pointSizeCombo->insertItem(i, QString::number(psize));
ui->pointSizeCombo->setCurrentIndex(i);
break;
}
}
QStringList subs = QFont::substitutes(ui->familySubstitutionCombo->currentText());