本文整理汇总了C++中QTextDocument::allFormats方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::allFormats方法的具体用法?C++ QTextDocument::allFormats怎么用?C++ QTextDocument::allFormats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::allFormats方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
QVector<QTextFormat> QTextDocumentProto::allFormats() const
{
QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
if (item)
return item->allFormats();
return QVector<QTextFormat>();
}
示例2: resolveFont
void tst_QTextFormat::resolveFont()
{
QTextDocument doc;
QTextCharFormat fmt;
fmt.setProperty(QTextFormat::ForegroundBrush, QColor(Qt::blue));
QCOMPARE(fmt.property(QTextFormat::ForegroundBrush).userType(), qMetaTypeId<QColor>());
QCOMPARE(fmt.property(QTextFormat::ForegroundBrush).value<QColor>(), QColor(Qt::blue));
fmt.setProperty(QTextFormat::FontItalic, true);
QTextCursor(&doc).insertText("Test", fmt);
QVector<QTextFormat> formats = doc.allFormats();
QCOMPARE(formats.count(), 3);
QVERIFY(formats.at(2).type() == QTextFormat::CharFormat);
fmt = formats.at(2).toCharFormat();
QVERIFY(!fmt.font().underline());
QVERIFY(fmt.hasProperty(QTextFormat::ForegroundBrush));
QFont f;
f.setUnderline(true);
doc.setDefaultFont(f);
formats = doc.allFormats();
fmt = formats.at(2).toCharFormat();
QVERIFY(fmt.font().underline());
QVERIFY(!fmt.hasProperty(QTextFormat::FontUnderline));
// verify that deleting a non-existent property does not affect the font resolving
QVERIFY(!fmt.hasProperty(QTextFormat::BackgroundBrush));
fmt.clearProperty(QTextFormat::BackgroundBrush);
QVERIFY(!fmt.hasProperty(QTextFormat::BackgroundBrush));
QVERIFY(!fmt.hasProperty(QTextFormat::FontUnderline));
QVERIFY(fmt.font().underline());
// verify that deleting an existent but font _unrelated_ property does not affect the font resolving
QVERIFY(fmt.hasProperty(QTextFormat::ForegroundBrush));
fmt.clearProperty(QTextFormat::ForegroundBrush);
QVERIFY(!fmt.hasProperty(QTextFormat::ForegroundBrush));
QVERIFY(!fmt.hasProperty(QTextFormat::FontUnderline));
QVERIFY(fmt.font().underline());
// verify that removing a font property _does_ clear the resolving
QVERIFY(fmt.hasProperty(QTextFormat::FontItalic));
fmt.clearProperty(QTextFormat::FontItalic);
QVERIFY(!fmt.hasProperty(QTextFormat::FontItalic));
QVERIFY(!fmt.hasProperty(QTextFormat::FontUnderline));
QVERIFY(!fmt.font().underline());
QVERIFY(!fmt.font().italic());
// reset
fmt = formats.at(2).toCharFormat();
QVERIFY(fmt.font().underline());
QVERIFY(!fmt.hasProperty(QTextFormat::FontUnderline));
// verify that _setting_ an unrelated property does _not_ affect the resolving
QVERIFY(!fmt.hasProperty(QTextFormat::IsAnchor));
fmt.setProperty(QTextFormat::IsAnchor, true);
QVERIFY(fmt.hasProperty(QTextFormat::IsAnchor));
QVERIFY(fmt.font().underline());
QVERIFY(!fmt.hasProperty(QTextFormat::FontUnderline));
// verify that setting a _related_ font property does affect the resolving
//
QVERIFY(!fmt.hasProperty(QTextFormat::FontStrikeOut));
fmt.setProperty(QTextFormat::FontStrikeOut, true);
QVERIFY(fmt.hasProperty(QTextFormat::FontStrikeOut));
QVERIFY(!fmt.font().underline());
QVERIFY(!fmt.hasProperty(QTextFormat::FontUnderline));
QVERIFY(fmt.font().strikeOut());
}