本文整理汇总了C++中QTextLayout::clearLayout方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextLayout::clearLayout方法的具体用法?C++ QTextLayout::clearLayout怎么用?C++ QTextLayout::clearLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextLayout
的用法示例。
在下文中一共展示了QTextLayout::clearLayout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateSingleLineLayout
/// Calculate single line layout for given text with specified font.
/// This function automatically add ellipsis text if the naural width
/// is larger than given region.
/// \layout The result layout.
/// \font The font object.
/// \string The text needs to be layouted.
/// \align Alignment.
/// \rect The region.
/// \ellipsis Add ellipse to left or right if necessary.
/// Returns the line height.
int calculateSingleLineLayout(QTextLayout & layout,
const QFont & font,
const QString & string,
const Qt::Alignment align,
const QRect & rect,
const Qt::TextElideMode ellipsis)
{
QFontMetrics fm(font);
// Check if we need to add ellipsis.
QString result_string = string;
int width = ellipsisText(string, fm, rect.width(),
ellipsis, result_string);
// Construct the layout.
layout.clearLayout();
layout.setCacheEnabled(false);
layout.setText(result_string);
layout.setFont(font);
layout.beginLayout();
QTextLine line = layout.createLine();
if (line.isValid())
{
line.setLineWidth(rect.width());
}
layout.endLayout();
// Calculate the position.
int x = rect.left();
int y = rect.top();
int h = static_cast<int>(line.height());
if (align & Qt::AlignHCenter)
{
x = ((rect.width() - width) >> 1) + x;
}