本文整理汇总了C++中QTextDocument::defaultTextOption方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::defaultTextOption方法的具体用法?C++ QTextDocument::defaultTextOption怎么用?C++ QTextDocument::defaultTextOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::defaultTextOption方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ensureTextLayouted
void QLabelPrivate::ensureTextLayouted() const
{
if (!textLayoutDirty)
return;
ensureTextPopulated();
if (control) {
QTextDocument *doc = control->document();
QTextOption opt = doc->defaultTextOption();
opt.setAlignment(QFlag(this->align));
if (this->align & Qt::TextWordWrap)
opt.setWrapMode(QTextOption::WordWrap);
else
opt.setWrapMode(QTextOption::ManualWrap);
doc->setDefaultTextOption(opt);
QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
fmt.setMargin(0);
doc->rootFrame()->setFrameFormat(fmt);
doc->setTextWidth(documentRect().width());
}
textLayoutDirty = false;
}
示例2: setShowWhitespace
void GenericCodeEditor::setShowWhitespace(bool show)
{
QTextDocument *doc = textDocument();
QTextOption opt( doc->defaultTextOption() );
if( show )
opt.setFlags( opt.flags() | QTextOption::ShowTabsAndSpaces );
else
opt.setFlags( opt.flags() & ~QTextOption::ShowTabsAndSpaces );
doc->setDefaultTextOption(opt);
}
示例3: drawStandBy_
void DanmakuMove::drawStandBy_(){
if (startPaintDMIndex_ <= dmCreater_->totalDMCount_) {
return;
}
if (!isNeedUpdateStandBy_)
return;
else
isNeedUpdateStandBy_ = false;
QFont font;
font.setBold(true);
font.setFamily(QString("Microsoft YaHei"));
font.setPixelSize(25);
QString styleStr = QString(
"<p>"
"<span style = \" font-size:%1px; color:#FF9DCB; \">%2< / span>"
"</p>");
QString standByStr = styleStr.arg(font.pixelSize()).arg(tr("Stand By"));
QTextDocument td;
td.setDefaultFont(font);
td.setDocumentMargin(10);
QTextOption op = td.defaultTextOption();
op.setAlignment(Qt::AlignHCenter);
td.setDefaultTextOption( op );
td.setHtml(standByStr);
td.setTextWidth(dmSideWidSize_.width());
QSize s = td.size().toSize();
if (standByPix_)
delete standByPix_;
standByPix_ = new QPixmap(QSize(dmSideWidSize_.width(), 60));
standByPix_->fill(Qt::transparent);
QPainter p(standByPix_);
p.setPen(QPen(QColor(0x49545A)));
p.setBrush(QBrush(QColor(0x49545A), Qt::SolidPattern));
p.setFont(font);
int border = 1;
QRect r(0, 0, standByPix_->width(), standByPix_->height());
p.setOpacity(0.6);
p.drawRoundedRect(r.adjusted(border, border, -border, -border), 3, 3);
td.drawContents(&p);
dmSideWidBKPixCache_->fill(Qt::transparent);
QPainter pSideDM(dmSideWidBKPixCache_);
pSideDM.drawPixmap(QPoint(0, dmSideWidBKPixCache_->height()-standByPix_->height()+border), *standByPix_);
}
示例4: setFlag
GraphicsTextItem::GraphicsTextItem(){
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
setFlag(QGraphicsItem::ItemIsFocusable);
setAcceptDrops(true);
setAcceptHoverEvents(true);
QTextDocument *tdocument = document();
tdocument->setModified(true);
QTextOption option = tdocument->defaultTextOption();
option.setAlignment(Qt::AlignHCenter);
tdocument->setDefaultTextOption(option);
//setTextWidth(tdocument->idealWidth());
setTextWidth(400);
}
示例5: layoutBlock
void TextDocumentLayout::layoutBlock(const QTextBlock &block)
{
QTextDocument *doc = document();
qreal margin = doc->documentMargin();
qreal blockMaximumWidth = 0;
qreal height = 0;
QTextLayout *tl = block.layout();
QTextOption option = doc->defaultTextOption();
tl->setTextOption(option);
int extraMargin = 0;
if (option.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) {
QFontMetrics fm(block.charFormat().font());
extraMargin += fm.width(QChar(0x21B5));
}
tl->beginLayout();
qreal availableWidth = d->width;
if (availableWidth <= 0) {
availableWidth = qreal(INT_MAX); // similar to text edit with pageSize.width == 0
}
availableWidth -= 2*margin + extraMargin;
qreal indentMargin = 0;
while (1) {
QTextLine line = tl->createLine();
if (!line.isValid())
break;
line.setLeadingIncluded(true);
line.setLineWidth(availableWidth - indentMargin);
line.setPosition(QPointF(margin + indentMargin, height));
if(!height) //enter only in the first iteration
{
indentMargin = indentWidth(block);
}
height += line.height();
blockMaximumWidth = qMax(blockMaximumWidth, line.naturalTextWidth() + 2*margin);
}
tl->endLayout();
int previousLineCount = doc->lineCount();
const_cast<QTextBlock&>(block).setLineCount(block.isVisible() ? tl->lineCount() : 0);
int lineCount = doc->lineCount();
bool emitDocumentSizeChanged = previousLineCount != lineCount;
if (blockMaximumWidth > d->maximumWidth) {
// new longest line
d->maximumWidth = blockMaximumWidth;
d->maximumWidthBlockNumber = block.blockNumber();
emitDocumentSizeChanged = true;
} else if (block.blockNumber() == d->maximumWidthBlockNumber && blockMaximumWidth < d->maximumWidth) {
// longest line shrinking
QTextBlock b = doc->firstBlock();
d->maximumWidth = 0;
QTextBlock maximumBlock;
while (b.isValid()) {
qreal blockMaximumWidth = blockWidth(b);
if (blockMaximumWidth > d->maximumWidth) {
d->maximumWidth = blockMaximumWidth;
maximumBlock = b;
}
b = b.next();
}
if (maximumBlock.isValid()) {
d->maximumWidthBlockNumber = maximumBlock.blockNumber();
emitDocumentSizeChanged = true;
}
}
if (emitDocumentSizeChanged)// && !d->blockDocumentSizeChanged)
emit documentSizeChanged(documentSize());
emit updateBlock(block);
}