本文整理汇总了C++中QTextOption::setWrapMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextOption::setWrapMode方法的具体用法?C++ QTextOption::setWrapMode怎么用?C++ QTextOption::setWrapMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextOption
的用法示例。
在下文中一共展示了QTextOption::setWrapMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QFrame
StyledLabel::StyledLabel(QWidget *parent)
: QFrame(parent),
_wrapMode(QTextOption::NoWrap),
_alignment(Qt::AlignVCenter|Qt::AlignLeft),
_toolTipEnabled(true),
_resizeMode(NoResize)
{
setMouseTracking(true);
QTextOption opt = _layout.textOption();
opt.setWrapMode(_wrapMode);
opt.setAlignment(_alignment);
_layout.setTextOption(opt);
}
示例2: initLayoutHelper
void ChatItem::initLayoutHelper(QTextLayout *layout, QTextOption::WrapMode wrapMode, Qt::Alignment alignment) const {
Q_ASSERT(layout);
layout->setText(data(MessageModel::DisplayRole).toString());
QTextOption option;
option.setWrapMode(wrapMode);
option.setAlignment(alignment);
layout->setTextOption(option);
QList<QTextLayout::FormatRange> formatRanges
= QtUi::style()->toTextLayoutList(formatList(), layout->text().length(), data(ChatLineModel::MsgLabelRole).toUInt());
layout->setAdditionalFormats(formatRanges);
}
示例3: QWidget
ItemSync::ItemSync(const QString &label, const QString &icon, ItemWidget *childItem)
: QWidget( childItem->widget()->parentWidget() )
, ItemWidgetWrapper(childItem, this)
, m_label( new QTextEdit(this) )
, m_icon( new IconWidget(icon, this) )
{
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->setSizeConstraint(QLayout::SetMinimumSize);
auto labelLayout = new QHBoxLayout;
connect( layout, &QVBoxLayout::destroyed,
labelLayout, &QHBoxLayout::deleteLater );
labelLayout->setContentsMargins(0, 0, 0, 0);
labelLayout->setSpacing(0);
labelLayout->addWidget(m_icon);
labelLayout->addWidget(m_label);
labelLayout->addStretch();
layout->addLayout(labelLayout);
QWidget *w = childItem->widget();
layout->addWidget(w);
w->setObjectName("item_child");
w->setParent(this);
m_label->setObjectName("item_child");
m_label->document()->setDefaultFont(font());
QTextOption option = m_label->document()->defaultTextOption();
option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
m_label->document()->setDefaultTextOption(option);
m_label->setReadOnly(true);
m_label->setUndoRedoEnabled(false);
m_label->setFocusPolicy(Qt::NoFocus);
m_label->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_label->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_label->setFrameStyle(QFrame::NoFrame);
m_label->setContextMenuPolicy(Qt::NoContextMenu);
m_label->viewport()->installEventFilter(this);
m_label->setPlainText(label);
}
示例4: initUi
void PsiTipLabel::initUi()
{
margin = 1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, nullptr, this);
setFrameStyle(QFrame::NoFrame);
doc = new QTextDocument(this);
QTextOption opt = doc->defaultTextOption();
opt.setWrapMode(QTextOption::WordWrap);
doc->setDefaultTextOption(opt);
doc->setUndoRedoEnabled(false);
doc->setDefaultFont(font());
ensurePolished();
setText(theText_);
}
示例5: textSize
QSizeF QwtRichTextEngine::textSize( const QFont &font,
int flags, const QString& text ) const
{
QwtRichTextDocument doc( text, flags, font );
QTextOption option = doc.defaultTextOption();
if ( option.wrapMode() != QTextOption::NoWrap )
{
option.setWrapMode( QTextOption::NoWrap );
doc.setDefaultTextOption( option );
doc.adjustSize();
}
return doc.size();
}
示例6: paintPlaceHolderForInvisbleItem
void FormEditorItem::paintPlaceHolderForInvisbleItem(QPainter *painter) const
{
qreal stripesWidth = 12;
QRegion innerRegion = QRegion(boundingRect().adjusted(stripesWidth, stripesWidth, -stripesWidth, -stripesWidth).toRect());
QRegion outerRegion = QRegion(boundingRect().toRect()) - innerRegion;
painter->setClipRegion(outerRegion);
painter->setClipping(true);
painter->fillRect(boundingRect().adjusted(1, 1, -1, -1), Qt::BDiagPattern);
painter->setClipping(false);
QString displayText = qmlItemNode().id();
if (displayText.isEmpty())
displayText = qmlItemNode().simplifiedTypeName();
QTextOption textOption;
textOption.setAlignment(Qt::AlignCenter);
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
if (boundingRect().width() > 60) {
painter->save();
QFont font;
font.setStyleHint(QFont::SansSerif);
font.setBold(true);
font.setPixelSize(14);
painter->setFont(font);
QFontMetrics fm(font);
if (fm.width(displayText) > (boundingRect().width() - 22) && displayText.length() > 4) {
displayText = fm.elidedText(displayText, Qt::ElideRight, boundingRect().width() - 22, Qt::TextShowMnemonic);
}
painter->setPen(QColor(255, 255, 255, 128));
painter->setCompositionMode(QPainter::CompositionMode_Exclusion);
painter->drawText(boundingRect().adjusted(-2, -2, 0,0), displayText, textOption);
painter->setFont(font);
painter->setPen(QColor(0, 0, 0, 255));
painter->drawText(boundingRect(), displayText, textOption);
painter->restore();
}
}
示例7: staticText
QStaticText ApiTraceFrame::staticText() const
{
if (!m_staticText.text().isEmpty())
return m_staticText;
QString richText =
QString::fromLatin1("<span style=\"font-weight:bold\">Frame %1</span>").arg(number);
m_staticText.setText(richText);
QTextOption opt;
opt.setWrapMode(QTextOption::NoWrap);
m_staticText.setTextOption(opt);
m_staticText.prepare();
return m_staticText;
}
示例8: viewItemTextSize
static QSize viewItemTextSize ( const QStyleOptionViewItemV4 *option )
{
QStyle *style = option->widget ? option->widget->style() : QApplication::style();
QTextOption textOption;
textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere );
QTextLayout textLayout;
textLayout.setTextOption ( textOption );
textLayout.setFont ( option->font );
textLayout.setText ( option->text );
const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, option, option->widget ) + 1;
QRect bounds ( 0,0,100 - 2*textMargin,600 );
qreal height = 0, widthUsed = 0;
viewItemTextLayout ( textLayout, bounds.width(), height, widthUsed );
const QSize size ( qCeil ( widthUsed ), qCeil ( height ) );
return QSize ( size.width() + 2 * textMargin, size.height() );
}
示例9: regenerate
void Text::regenerate()
{
if (!doc) {
doc = DocumentCache::getInstance().pop();
dirty = true;
}
if (dirty) {
doc->setDefaultFont(defFont);
if (elide) {
QFontMetrics metrics = QFontMetrics(defFont);
QString elidedText = metrics.elidedText(text, Qt::ElideRight, qRound(width));
doc->setPlainText(elidedText);
} else {
doc->setDefaultStyleSheet(defStyleSheet);
doc->setHtml(text);
}
// wrap mode
QTextOption opt;
opt.setWrapMode(elide ? QTextOption::NoWrap : QTextOption::WrapAtWordBoundaryOrAnywhere);
doc->setDefaultTextOption(opt);
// width
doc->setTextWidth(width);
doc->documentLayout()->update();
// update ascent
if (doc->firstBlock().layout()->lineCount() > 0)
ascent = doc->firstBlock().layout()->lineAt(0).ascent();
// let the scene know about our change in size
if (size != idealSize())
prepareGeometryChange();
// get the new width and height
size = idealSize();
dirty = false;
}
// if we are not visible -> free mem
if (!keepInMemory)
freeResources();
}
示例10: init
void TextItem::init()
{
setTextInteractionFlags(Qt::TextEditorInteraction);
setFlag(ItemIsSelectable, true);
setFlag(ItemIsFocusable, true);
QTextOption options;
options.setWrapMode(QTextOption::NoWrap);
options.setAlignment(Qt::AlignCenter);
document()->setDefaultTextOption(options);
connect(document(), &QTextDocument::contentsChanged, this, &TextItem::checkText);
QFont f = font();
f.setPixelSize(13);
setFont(f);
}
示例11: addBox
void PrintOut::addBox(int percent, const QString &text, Style style, Qt::Alignment halign)
{
QTextOption options;
options.setAlignment(halign | Qt::AlignTop);
options.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
QFont f = f10;
if (style == Strong)
f.setBold(true);
else if (style == Emphasis)
f.setItalic(true);
int wd = hsize * percent / 100;
QRect r(cp.rect.x() + cp.rect.width(), 0, wd, vsize);
const int ht = static_cast<int>(p.boundingRect(r, text, options).height());
Box b(r, text, f, options);
cp.boxes.append(b);
cp.rect.setSize(QSize(cp.rect.width() + wd, qMax(cp.rect.height(), ht)));
}
示例12: render_sequence
void render_sequence( QPainter * painter, const QStyleOptionViewItem& option, const QString& text ) const {
painter->save();
QStyleOptionViewItemV4 op = option;
QTextDocument document;
QTextOption to;
to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
document.setDefaultTextOption( to );
QFont font;
font.setFamily( "Consolas" );
document.setDefaultFont( font );
document.setTextWidth( op.rect.width() );
document.setHtml( text );
op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter );
painter->translate( op.rect.topLeft() );
QRect clip( 0, 0, op.rect.width(), op.rect.height() );
document.drawContents( painter, clip );
painter->restore();
}
示例13: paintEvent
void FlightItem::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
const int i = (m_landscape ? 1 : 0);
painter.setPen(palette().color(QPalette::BrightText));
painter.drawText(QRect(columns[i][0] - 2, 0, columns[i][1] - columns[i][0], height()), m_scheduleTime.time().toString("hhmm"));
painter.drawText(QRect(columns[i][1] - 2, 0, columns[i][2] - columns[i][1], height()), m_flightID);
if (m_direction == FlightTimes::Arrivals)
painter.drawText(QRect(columns[i][2] - 2, 0, columns[i][3] - columns[i][2], height()), m_beltNumber);
else
painter.drawText(QRect(columns[i][2] - 2, 0, columns[i][3] - columns[i][2], height()), m_gate);
QTextOption option;
option.setWrapMode(QTextOption::NoWrap);
const QString name = (m_routeAirportNames.isEmpty() ? m_airportName : m_routeAirportNames);
int last = width() > columns[i][5] ? columns[i][5] : columns[i][4];
painter.drawText(QRect(columns[i][3] - 2, 0, last - columns[i][3], height()), fontMetrics().elidedText(name, Qt::ElideRight, last - columns[i][3]), option);
painter.drawText(QRect(last - 2, 0, width() - last, height()), m_statusText, option);
}
示例14: paintEvent
void HelpWidget::paintEvent(QPaintEvent* e)
{
Q_UNUSED(e);
QRectF r = rect().adjusted(1, 1, -1, -1);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(QColor(187, 174, 105));
p.setBrush(QColor(242, 238, 184));
p.drawRoundedRect(r, 4, 4);
p.setPen(QColor(104, 74, 64));
p.setFont(mFont);
QTextOption options;
options.setWrapMode(QTextOption::WordWrap);
options.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
p.drawText(rect().adjusted(5, 5, -5, -5), mText, options);
}
示例15: initDocument
void SenderChatItem::initDocument(QTextDocument *doc)
{
// Hide double sender names
QModelIndex lastIndex = model()->index(row()-1, column());
if (lastIndex.isValid()
&& data(MessageModel::TypeRole).toInt() == Message::Plain
&& model()->data(lastIndex, MessageModel::TypeRole).toInt() == Message::Plain
&& (data(MessageModel::FlagsRole).toInt() & Message::Self) == (model()->data(lastIndex, MessageModel::FlagsRole).toInt() & Message::Self)) {
doc->setPlainText("");
}
else {
doc->setPlainText(data(MessageModel::DisplayRole).toString());
}
doc->setTextWidth(width());
QTextOption o;
o.setWrapMode(QTextOption::NoWrap);
doc->setDefaultTextOption(o);
}