本文整理汇总了C++中QTextDocument::setDefaultStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::setDefaultStyleSheet方法的具体用法?C++ QTextDocument::setDefaultStyleSheet怎么用?C++ QTextDocument::setDefaultStyleSheet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::setDefaultStyleSheet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintText
void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p)
{
bool preferRichText = textFormat == Qt::RichText
|| (textFormat == Qt::AutoText && Qt::mightBeRichText(text));
if (!preferRichText) {
QTextLayout textLayout;
textLayout.setText(text);
textLayout.setFont(font);
textLayout.setTextOption(textOption);
qreal leading = QFontMetricsF(font).leading();
qreal height = -leading;
textLayout.beginLayout();
while (1) {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
if (textWidth >= 0.0)
line.setLineWidth(textWidth);
height += leading;
line.setPosition(QPointF(0.0, height));
height += line.height();
}
textLayout.endLayout();
actualSize = textLayout.boundingRect().size();
textLayout.draw(p, topLeftPosition);
} else {
QTextDocument document;
#ifndef QT_NO_CSSPARSER
QColor color = p->pen().color();
document.setDefaultStyleSheet(QString::fromLatin1("body { color: #%1%2%3 }")
.arg(QString::number(color.red(), 16), 2, QLatin1Char('0'))
.arg(QString::number(color.green(), 16), 2, QLatin1Char('0'))
.arg(QString::number(color.blue(), 16), 2, QLatin1Char('0')));
#endif
document.setDefaultFont(font);
document.setDocumentMargin(0.0);
#ifndef QT_NO_TEXTHTMLPARSER
document.setHtml(text);
#else
document.setPlainText(text);
#endif
if (textWidth >= 0.0)
document.setTextWidth(textWidth);
else
document.adjustSize();
document.setDefaultTextOption(textOption);
p->save();
p->translate(topLeftPosition);
document.drawContents(p);
p->restore();
if (textWidth >= 0.0)
document.adjustSize(); // Find optimal size
actualSize = document.size();
}
}
示例2: paintEvent
//.........这里部分代码省略.........
// x(t) = at + b
a = mFitLineX[1];
b = mFitLineX[0];
// y(t) = At^2 + Bt + C
A = mFitParabolaY[2];
B = mFitParabolaY[1];
C = mFitParabolaY[0];
// y(x) = Ux^2 + Vx + W
U = A/a/a;
V = B/a - 2*A*b/a/a;
W = A*b*b/a/a - B*b/a + C;
// Show the fit parabola
if (mShowParabola) {
if (mFitLocked) {
painter.setPen(fitLockPen);
} else
{
painter.setPen(fitPen);
}
QPointF p1(0, W);
QPointF p2(mProjSize.width(),
U*mProjSize.width()*mProjSize.width() +
V*mProjSize.width() + W);
QPointF c(0.5*mProjSize.width(), W + .5*mProjSize.width()*V);
QPainterPath fitPath(relPointToWindow(p1));
fitPath.quadTo(relPointToWindow(c), relPointToWindow(p2));
painter.drawPath(fitPath);
}
// Draw the predicted y(t) and x(t) equation
if (mShowParam) {
dataHtml << QString("y(t) = %1 t<sup>2</sup> + %2 t + %3")
.arg(A, 0, 'f', 3)
.arg(B, 0, 'f', 3)
.arg(C, 0, 'f', 3)
<< QString("x(t) = %1 t + %2")
.arg(a, 0, 'f', 3)
.arg(b, 0, 'f', 3);
}
}
if (!mMarkedPoints.empty()) {
t0 = mMarkedPoints.at(0).t();
}
//QStringList markHtml;
QRectF markRect;
QFont markFont = painter.font();
markFont.setPointSize(mFontSize);
int mMarkRadius = mPointRadius*0.8;
// Draw marked points
painter.setFont(markFont);
for (predsIter = mMarkedPoints.begin(); predsIter != mMarkedPoints.end();
++predsIter) {
painter.setPen(markPen);
dataHtml << QString("%1: (%2, %3, %4)")
.arg(j)
.arg(predsIter->t()-t0, 0, 'f', 3)
.arg(predsIter->bbox().center().x(), 0, 'f', 3)
.arg(predsIter->bbox().center().y(), 0, 'f', 3);
markRect = QRectF((relPointToWindow(
(*predsIter).bbox().center()) -
QPointF(mMarkRadius/2,mMarkRadius/2)),
QSizeF(mMarkRadius,mMarkRadius));
painter.setBrush(background);
painter.drawEllipse(markRect);
painter.setBrush(normalBrush);
painter.drawText(markRect,
Qt::AlignCenter|Qt::TextDontClip,
QString("%1").arg(j));
j++;
}
if (!dataHtml.empty()) {
QTextDocument td;
td.setDefaultStyleSheet(
QString("body {"
" color: rgb(255,255,255);"
" font-size: %1pt;"
"}")
.arg(mFontSize));
td.setHtml(QString(
"<body>%1</body>")
.arg(dataHtml.join("<br>"))
);
td.drawContents(&painter);
}
painter.end();
}