void TextBrowserHelpWidget::setSource(const QUrl &name)
{
    QTextBrowser::setSource(name);

    QTextCursor cursor(document());
    while (!cursor.atEnd()) {
        QTextBlockFormat fmt = cursor.blockFormat();
        if (fmt.hasProperty(QTextFormat::LineHeightType) && fmt.lineHeightType() == QTextBlockFormat::FixedHeight) {
           fmt.setProperty(QTextFormat::LineHeightType, QTextBlockFormat::MinimumHeight);
           cursor.setBlockFormat(fmt);
        }
        if (!cursor.movePosition(QTextCursor::NextBlock))
            break;
    }
}
Beispiel #2
0
void MarkdownHighlighter::applyLineHeight()
{
	QTextBlock block = document->firstBlock();
	while (block.isValid()) {
		QTextCursor cursor(block);
		QTextBlockFormat format = cursor.blockFormat();
		// Don't apply lineHeight if it's already applied it to this block
		if (format.lineHeightType() != QTextBlockFormat::ProportionalHeight) {
			format.setLineHeight(130, QTextBlockFormat::ProportionalHeight);
			// joining previous edit is crucial, otherwise formatting changes are recorded
			// as separate operations in undo/redo stack, and pressing Ctrl-Z undoes
			// line height changes, clearly not what we want
			cursor.joinPreviousEditBlock();
			cursor.setBlockFormat(format);
			cursor.endEditBlock();
		}
		block = block.next();
	}
}