本文整理汇总了C++中QTextLine::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextLine::setPosition方法的具体用法?C++ QTextLine::setPosition怎么用?C++ QTextLine::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextLine
的用法示例。
在下文中一共展示了QTextLine::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: layoutText
void TextLabel::layoutText(QTextLayout &layout, const QString &text, const QSize &constraints)
{
QFontMetrics metrics(layout.font());
int leading = metrics.leading();
int height = 0;
int maxWidth = constraints.width();
int widthUsed = 0;
int lineSpacing = metrics.lineSpacing();
QTextLine line;
layout.setText(text);
layout.beginLayout();
while ((line = layout.createLine()).isValid()) {
height += leading;
// Make the last line that will fit infinitely long.
// drawTextLayout() will handle this by fading the line out
// if it won't fit in the constraints.
if (height + 2 * lineSpacing > constraints.height()) {
line.setPosition(QPoint(0, height));
break;
}
line.setLineWidth(maxWidth);
line.setPosition(QPoint(0, height));
height += int(line.height());
widthUsed = int(qMax(qreal(widthUsed), line.naturalTextWidth()));
}
layout.endLayout();
}
示例2: init
void UserIcon::init(){
QString text = tr(user_->name().c_str());
layout_ = new QTextLayout(text,
d_->users_scene()->font());
QFontMetricsF fm(d_->users_scene()->font());
layout_->beginLayout();
QTextLine line = layout_->createLine();
//line.setNumColumns(1);
QSizeF text_size_ = fm.boundingRect(text).size();
// TODO: Figure out what these numbers are all about, why width/4, height/4
//line.setPosition(QPointF(s.width()/4.0,
// -s.height()/4.0));
line.setPosition(QPointF());
layout_->endLayout();
layout_->setCacheEnabled(true);
menu_ = new QMenu(tr(user_->name().c_str()));
show_on_map_ = new QAction(tr("Show on map"), this);
menu_->addAction(show_on_map_);
connect(show_on_map_, SIGNAL(triggered()),
this,
SLOT(activateLastNode()));
focus_on_ = new QAction(tr("Focus on"), this);
menu_->addAction(focus_on_);
connect(focus_on_, SIGNAL(triggered()),
this,
SLOT(focusOnLastNode()));
updateDrawRect();
}
示例3: recalculateTextLayout
void TestResultDelegate::recalculateTextLayout(const QModelIndex &index, const QString &output,
const QFont &font, int width) const
{
if (m_lastProcessedIndex == index && m_lastProcessedFont == font)
return;
const QFontMetrics fm(font);
const int leading = fm.leading();
const int fontHeight = fm.height();
m_lastProcessedIndex = index;
m_lastProcessedFont = font;
m_lastCalculatedHeight = 0;
m_lastCalculatedLayout.clearLayout();
m_lastCalculatedLayout.setText(output);
m_lastCalculatedLayout.setFont(font);
QTextOption txtOption;
txtOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
m_lastCalculatedLayout.setTextOption(txtOption);
m_lastCalculatedLayout.beginLayout();
while (true) {
QTextLine line = m_lastCalculatedLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(width);
m_lastCalculatedHeight += leading;
line.setPosition(QPoint(0, m_lastCalculatedHeight));
m_lastCalculatedHeight += fontHeight;
}
m_lastCalculatedLayout.endLayout();
}
示例4: drawDisplay
void PluginListDelegate::drawDisplay(QPainter* painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
{
QTextDocument textDocument;
textDocument.setHtml(text);
QTextLayout textLayout(textDocument.begin());
textLayout.setFont(option.font);
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0) + 1;
QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding
textLayout.beginLayout();
qreal height = 0;
while (1) {
QTextLine line = textLayout.createLine();
if (!line.isValid()) {
break;
}
line.setLineWidth(textRect.width());
height += 3;
line.setPosition(QPoint(0, height));
height += line.height();
}
textLayout.endLayout();
textLayout.draw(painter, QPointF(textRect.left(), textRect.top()));
}
示例5: paint_QTextLayout
void paint_QTextLayout(QPainter &p, bool useCache)
{
static bool first = true;
static QTextLayout *textLayout[lines];
if (first) {
for (int i = 0; i < lines; ++i) {
textLayout[i] = new QTextLayout(strings[i]);
int leading = p.fontMetrics().leading();
qreal height = 0;
qreal widthUsed = 0;
textLayout[i]->setCacheEnabled(useCache);
textLayout[i]->beginLayout();
while (1) {
QTextLine line = textLayout[i]->createLine();
if (!line.isValid())
break;
line.setLineWidth(lineWidth);
height += leading;
line.setPosition(QPointF(0, height));
height += line.height();
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout[i]->endLayout();
}
first = false;
}
for (int i = 0; i < count; ++i) {
for (int j = 0; j < lines; ++j) {
textLayout[j]->draw(&p, QPoint(0, j*spacing));
}
}
}
示例6: layoutText
void YTDelegate::layoutText(QTextLayout& textLayout, QString text, QSize constraint) const
{
QTextOption textOption(Qt::AlignJustify);
textLayout.setTextOption(textOption);
textLayout.setText(text);
textLayout.beginLayout();
int lHeight = 0;
while(true){
QTextLine line = textLayout.createLine();
if(!line.isValid())
break;
line.setLineWidth(constraint.width());
line.setPosition(QPointF(0, lHeight));
if(lHeight + line.height() > constraint.height())
{
QTextLine lastLine = textLayout.lineAt(textLayout.lineCount() - 2);
QString lastString = text.mid(lastLine.textStart());
QFontMetrics fm(textLayout.font());
text.chop(lastString.length());
text += fm.elidedText(lastString, Qt::ElideRight, constraint.width()-1);
textLayout.endLayout();
layoutText(textLayout, text, constraint);
return;
}
lHeight += line.height();
lHeight += line.leading();
}
textLayout.endLayout();
}
示例7: textFontMetrics
//virtual
void PixButton::redoLabelTextLayout()
{
//TODO: somewhat wasteful. If there is no label, should just exit early and leave a layout that will be left unrendered by paint()
m_textLayoutObject.clearLayout();
m_textLayoutObject.setText(m_label);
m_textLayoutObject.setFont(m_textFont);
QTextOption textOpts;
textOpts.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
textOpts.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
m_textLayoutObject.setTextOption(textOpts);
QFontMetrics textFontMetrics(m_textFont);
int leading = textFontMetrics.leading();
int rise = textFontMetrics.ascent();
qreal height = 0;
m_textLayoutObject.beginLayout();
while (height < m_labelMaxGeom.height()) {
QTextLine line = m_textLayoutObject.createLine();
if (!line.isValid())
break;
line.setLineWidth(m_labelMaxGeom.width());
if (m_textLayoutObject.lineCount() > 1)
{
height += leading;
}
line.setPosition(QPointF(0, height));
height += line.height();
}
height = qMin((quint32)DimensionsGlobal::roundUp(height),(quint32)m_labelMaxGeom.height());
height = DimensionsGlobal::roundDown(height) - (DimensionsGlobal::roundDown(height) % 2); //force to an even #
m_textLayoutObject.endLayout();
//TODO: PIXEL-ALIGN
m_labelGeom = DimensionsGlobal::realRectAroundRealPoint(QSizeF(m_textLayoutObject.boundingRect().width(),height)).toAlignedRect();
}
示例8: doLayout
void ChatItem::doLayout(QTextLayout *layout) const {
layout->beginLayout();
QTextLine line = layout->createLine();
if(line.isValid()) {
line.setLineWidth(width());
line.setPosition(QPointF(0,0));
}
layout->endLayout();
}
示例9: setDisplayedName
void LayerView::setDisplayedName(const QString& s)
{
m_displayedName = s;
m_textcache.setText(s);
m_textcache.beginLayout();
QTextLine line = m_textcache.createLine();
line.setPosition(QPointF{0., 0.});
m_textcache.endLayout();
update();
}
示例10: viewItemTextLayout
// Origin: Qt
static void viewItemTextLayout ( QTextLayout &textLayout, int lineWidth, qreal &height, qreal &widthUsed )
{
height = 0;
widthUsed = 0;
textLayout.beginLayout();
while ( true )
{
QTextLine line = textLayout.createLine();
if ( !line.isValid() )
break;
line.setLineWidth ( lineWidth );
line.setPosition ( QPointF ( 0, height ) );
height += line.height();
widthUsed = qMax ( widthUsed, line.naturalTextWidth() );
}
textLayout.endLayout();
}
示例11: doTextLayout
// copied from QItemDelegate for drawDisplay
QSizeF doTextLayout(QTextLayout *textLayout, int lineWidth)
{
qreal height = 0;
qreal widthUsed = 0;
textLayout->beginLayout();
while (true) {
QTextLine line = textLayout->createLine();
if (!line.isValid())
break;
line.setLineWidth(lineWidth);
line.setPosition(QPointF(0, height));
height += line.height();
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout->endLayout();
return QSizeF(widthUsed, height);
}
示例12: layoutText
static int layoutText(QTextLayout *layout, int maxWidth) {
qreal height = 0;
int textWidth = 0;
layout->beginLayout();
while (true) {
QTextLine line = layout->createLine();
if (!line.isValid()) {
break;
}
line.setLineWidth(maxWidth);
line.setPosition(QPointF(0, height));
height += line.height();
textWidth = qMax(textWidth, qRound(line.naturalTextWidth() + 0.5));
}
layout->endLayout();
return textWidth;
}
示例13: doTextLayout
QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const
{
qreal height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (true) {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(lineWidth);
line.setPosition(QPointF(0, height));
height += line.height();
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout.endLayout();
return QSizeF(widthUsed, height);
}
示例14: paintEvent
void Window::paintEvent(QPaintEvent *event)
{
//! [0]
QTextLayout textLayout(text, font);
qreal margin = 10;
qreal radius = qMin(width()/2.0, height()/2.0) - margin;
QFontMetrics fm(font);
qreal lineHeight = fm.height();
qreal y = 0;
textLayout.beginLayout();
while (1) {
// create a new line
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
qreal x1 = qMax(0.0, pow(pow(radius,2)-pow(radius-y,2), 0.5));
qreal x2 = qMax(0.0, pow(pow(radius,2)-pow(radius-(y+lineHeight),2), 0.5));
qreal x = qMax(x1, x2) + margin;
qreal lineWidth = (width() - margin) - x;
line.setLineWidth(lineWidth);
line.setPosition(QPointF(x, margin+y));
y += line.height();
}
textLayout.endLayout();
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(rect(), Qt::white);
painter.setBrush(QBrush(Qt::black));
painter.setPen(QPen(Qt::black));
textLayout.draw(&painter, QPoint(0,0));
painter.setBrush(QBrush(QColor("#a6ce39")));
painter.setPen(QPen(Qt::black));
painter.drawEllipse(QRectF(-radius, margin, 2*radius, 2*radius));
painter.end();
//! [0]
}
示例15: layoutText
qreal QmlConsoleItemDelegate::layoutText(QTextLayout &tl, int width,
bool *showFileLineInfo) const
{
qreal height = 0;
tl.beginLayout();
while (true) {
QTextLine line = tl.createLine();
if (!line.isValid())
break;
line.setLeadingIncluded(true);
line.setLineWidth(width);
if (width < line.naturalTextWidth() && showFileLineInfo)
*showFileLineInfo = false;
line.setPosition(QPoint(0, height));
height += line.height();
}
tl.endLayout();
return height;
}