本文整理汇总了C++中QTextOption::alignment方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextOption::alignment方法的具体用法?C++ QTextOption::alignment怎么用?C++ QTextOption::alignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextOption
的用法示例。
在下文中一共展示了QTextOption::alignment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: alignment
int TextOption::alignment( lua_State * L ) // const Qt::Alignment
{
QTextOption* lhs = ValueInstaller2<QTextOption>::check( L, 1 );
Qt::Alignment alignment=(Qt::Alignment) lhs->alignment();
Util::push( L, alignment);
return 1;
}
示例2: drawDisplay
//.........这里部分代码省略.........
before.format = m_cachedHighlights[i - 1].format;
additionalFormats.append(before);
}
QTextLayout::FormatRange format;
format.start = m_cachedHighlights[i].start - m_currentColumnStart;
format.length = m_cachedHighlights[i].length;
format.format = m_cachedHighlights[i].format;
additionalFormats.append(format);
}
if (!additionalFormats.isEmpty()) {
missingFormats = text.length() - (additionalFormats.back().length + additionalFormats.back().start);
}
if (missingFormats > 0) {
QTextLayout::FormatRange format;
format.start = text.length() - missingFormats;
format.length = missingFormats;
QTextCharFormat fm;
fm.setForeground(option.palette.text());
format.format = fm;
additionalFormats.append(format);
}
if (m_backgroundColor.isValid()) {
QColor background = m_backgroundColor;
// qCDebug(LOG_KTE) << text << "background:" << background.name();
//Now go through the formats, and make sure the contrast background/foreground is readable
for (int a = 0; a < additionalFormats.size(); ++a) {
QColor currentBackground = background;
if (additionalFormats[a].format.hasProperty(QTextFormat::BackgroundBrush)) {
currentBackground = additionalFormats[a].format.background().color();
}
QColor currentColor = additionalFormats[a].format.foreground().color();
double currentContrast = readabilityContrast(currentColor, currentBackground);
QColor invertedColor(0xffffffff - additionalFormats[a].format.foreground().color().rgb());
double invertedContrast = readabilityContrast(invertedColor, currentBackground);
// qCDebug(LOG_KTE) << "values:" << invertedContrast << currentContrast << invertedColor.name() << currentColor.name();
if (invertedContrast > currentContrast) {
// qCDebug(LOG_KTE) << text << additionalFormats[a].length << "switching from" << currentColor.name() << "to" << invertedColor.name();
QBrush b(additionalFormats[a].format.foreground());
b.setColor(invertedColor);
additionalFormats[a].format.setForeground(b);
}
}
}
for (int a = additionalFormats.size() - 1; a >= 0; --a) {
if (additionalFormats[a].length == 0) {
additionalFormats.removeAt(a);
} else {
///For some reason the text-formats seem to be invalid in some way, sometimes
///@todo Fix this properly, it sucks not copying everything over
QTextCharFormat fm;
fm.setForeground(QBrush(additionalFormats[a].format.foreground().color()));
fm.setBackground(additionalFormats[a].format.background());
fm.setUnderlineStyle(additionalFormats[a].format.underlineStyle());
fm.setUnderlineColor(additionalFormats[a].format.underlineColor());
fm.setFontWeight(additionalFormats[a].format.fontWeight());
additionalFormats[a].format = fm;
}
}
// qCDebug(LOG_KTE) << "Highlights for text [" << text << "] col start " << m_currentColumnStart << ":";
// foreach (const QTextLayout::FormatRange& fr, additionalFormats)
// qCDebug(LOG_KTE) << fr.start << " len " << fr.length << "foreground" << fr.format.foreground() << "background" << fr.format.background();
layout.setAdditionalFormats(additionalFormats);
QTextOption to;
to.setAlignment( static_cast<Qt::Alignment>(m_cachedAlignment | option.displayAlignment) );
to.setWrapMode(QTextOption::WrapAnywhere);
layout.setTextOption(to);
layout.beginLayout();
QTextLine line = layout.createLine();
// Leave some extra space when the text is right-aligned
line.setLineWidth(rect.width() - (option.displayAlignment == Qt::AlignRight ? 8 : 0));
layout.endLayout();
//We need to do some hand layouting here
if (to.alignment() & Qt::AlignBottom) {
layout.draw(painter, QPoint(rect.left(), rect.bottom() - (int)line.height()));
} else {
layout.draw(painter, rect.topLeft());
}
return;
//if (painter->fontMetrics().width(text) > textRect.width() && !text.contains(QLatin1Char('\n')))
//str = elidedText(option.fontMetrics, textRect.width(), option.textElideMode, text);
//qt_format_text(option.font, textRect, option.displayAlignment, str, 0, 0, 0, 0, painter);
}