当前位置: 首页>>代码示例>>C++>>正文


C++ QTextDocument::adjustSize方法代码示例

本文整理汇总了C++中QTextDocument::adjustSize方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::adjustSize方法的具体用法?C++ QTextDocument::adjustSize怎么用?C++ QTextDocument::adjustSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextDocument的用法示例。


在下文中一共展示了QTextDocument::adjustSize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sizeHint

QSize KsirkChatItem::sizeHint(const QStyleOptionViewItem &option)
{
  unsigned int w = 0;
  QTextDocument fake; // used to allow to compute lines height
  fake.setHtml("gpl");
  fake.setDefaultFont(option.font);
  fake.adjustSize();
  fake.setTextWidth ( -1 );
  
  qreal h = fake.size().height();
  for (int i = 0 ; i < m_order.size(); i++)
  {
    QTextDocument rt;
    rt.setHtml(m_strings[i]);
    rt.adjustSize();
    rt.setTextWidth ( -1 );
    QPixmap px(rt.size().toSize());
    switch (m_order[i])
    {
    case Text:
      w += px.width();
    break;
    case Pixmap:
      if (! m_pixmaps[i].isNull())
      {
        QPixmap scaled = m_pixmaps[i].scaledToHeight((int)h);
         w+= scaled.width();
      }
    break;
    default: ;
    }
  }
//   kDebug() << "KsirkChatItem::sizeHint: " << QSize(w,h) << endl;
  return QSize(w,(int)h);
}
开发者ID:KDE,项目名称:ksirk,代码行数:35,代码来源:KsirkChatItem.cpp

示例2: drawHtmlLine

void drawHtmlLine(QPainter *painter, const QFont font, QRect rect, QString text, bool multiline,
                  bool leftAligned) {
    if(!painter){return;}

    painter->save();

    QTextDocument displayDoc;
    setUpDisplayDoc(displayDoc, font);
    if(!leftAligned){
        text = QString("<div align=\"right\">") + text + "</div>";

    }

    displayDoc.setHtml(text);
    //multiline == false - Normally
    if(multiline){
        displayDoc.setTextWidth(rect.width());
    } else {displayDoc.setTextWidth(-1);}


    painter->translate(rect.topLeft());

    if(multiline){ displayDoc.adjustSize(); }

    rect.moveTopLeft(QPoint(0,0));
    displayDoc.drawContents(painter, rect);

    painter->restore();

}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例3: paint

void KsirkChatItem::paint(QPainter* p, 
                const QStyleOptionViewItem &option, int row)
{
//   kError() << "KsirkChatItem::paint";
  Q_UNUSED(row);

  QTextDocument fake; // used to allow to compute lines height
  fake.setHtml("gpl");
  fake.setDefaultFont(option.font);
  fake.adjustSize();
  fake.setTextWidth ( -1 );
  
  qreal h = fake.size().height();
  unsigned int x = 0;
  for (int i = 0 ; i < m_order.size(); i++)
  {
    QTextDocument rt;
    rt.setHtml(m_strings[i]);
    rt.setDefaultFont(option.font);
    rt.adjustSize();
    rt.setTextWidth ( -1 );
    QPixmap px(rt.size().toSize());
    px.fill();
    QPainter pa(&px);
    rt.drawContents(&pa);
    switch (m_order[i])
    {
    case Text:
//       kDebug() << "  paint string '" << m_strings[i] << "' at " << x << ", " << row*h << endl;
      p->drawPixmap(option.rect.x()+x,option.rect.y(),px);
      x += px.width();
    break;
    case Pixmap:
      if (! m_pixmaps[i].isNull())
      {
//         kDebug() << "  paint pixmap at " << x << ", " << row*h << endl;
        QPixmap scaled = m_pixmaps[i].scaledToHeight((int)h);
        p->drawPixmap(option.rect.x()+x,option.rect.y(),scaled);
        x+= scaled.width();
      }
    break;
    default: ;
    }
  }
}
开发者ID:KDE,项目名称:ksirk,代码行数:45,代码来源:KsirkChatItem.cpp

示例4: sizeHint

QSize AppClassTreeDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
    QStyleOptionViewItemV4 options = option;
    initStyleOption(&options, index);

    QTextDocument doc;
    doc.setHtml(options.text);
    doc.setTextWidth(options.rect.width());
    doc.adjustSize();
    return QSize(doc.idealWidth(), doc.size().height());
}
开发者ID:Busti,项目名称:LCDHost,代码行数:11,代码来源:AppClassTreeDelegate.cpp

示例5: drawInfobox

void MeasureToolPlugin::drawInfobox( GeoPainter *painter ) const
{
    QString boxContent;

    if (m_paintMode == Polygon) {
        boxContent += "<strong>" + tr("Polygon Ruler") + ":</strong><br/>\n";
    } else /* Circular */ {
        boxContent += "<strong>" + tr("Circle Ruler") + ":</strong><br/>\n";
    }
    if (m_paintMode == Polygon) {
        boxContent += tr("Total Distance: %1<br/>\n").arg( meterToPreferredUnit(m_totalDistance) );
        if (m_showPolygonArea)
            boxContent += tr("Area: %1<br/>\n").arg( meterToPreferredUnit(m_polygonArea, true) );
        if (m_showPerimeter)
            boxContent += tr("Perimeter: %1<br/>\n").arg( meterToPreferredUnit(m_perimeter) );
    } else /* Circular */ {
        if (m_showRadius)
            boxContent += tr("Radius: %1<br/>\n").arg( meterToPreferredUnit(m_radius) );
        if (m_showCircumference)
            boxContent += tr("Circumference: %1<br/>\n").arg( meterToPreferredUnit(m_circumference) );
        if (m_showCircularArea)
            boxContent += tr("Area: %1<br/>\n").arg( meterToPreferredUnit(m_circularArea, true) );
    }

    painter->setPen( QColor( Qt::black ) );
    painter->setBrush( QColor( 192, 192, 192, 192 ) );

    QTextDocument doc;
    doc.setHtml(boxContent);
    doc.setDefaultFont(m_font_regular);
    doc.adjustSize();
    QSizeF pageSize = doc.size();

    painter->drawRect( 10, 105, 10 + pageSize.width(), pageSize.height() );
    QTransform transform;
    transform.translate(15, 110);
    painter->setTransform(transform);
    doc.drawContents(painter);
    painter->setTransform(QTransform());
}
开发者ID:PayalPradhan,项目名称:marble,代码行数:40,代码来源:MeasureToolPlugin.cpp

示例6: paintText

void QStaticTextPrivate::paintText(const QPointF &pos, QPainter *p)
{
    bool preferRichText = textFormat == Qt::RichText
                          || (textFormat == Qt::AutoText && Qt::mightBeRichText(text));

    if (!preferRichText) {
        if (maximumSize.isValid()) {
            QRectF boundingRect;
            p->drawText(QRectF(pos, maximumSize), Qt::TextWordWrap, text, &boundingRect);

            actualSize = boundingRect.size();
            needsClipRect = boundingRect.width() > maximumSize.width()
                            || boundingRect.height() > maximumSize.height();
        } else {
            p->drawText(pos, text);
            needsClipRect = false;

            QFontMetrics fm(font);
            actualSize = fm.boundingRect(text).size();
        }
    } else {
        QTextDocument document;
        document.setDefaultFont(font);
        document.setHtml(text);

        QRectF rect = maximumSize.isValid() ? QRectF(pos, maximumSize) : QRectF();
        document.adjustSize();
        p->save();
        p->translate(pos);
        document.drawContents(p, rect);        
        p->restore();
        actualSize = document.size();
        needsClipRect = maximumSize.isValid()
                        && (actualSize.width() > maximumSize.width()
                            || actualSize.height() > maximumSize.height());
    }
}
开发者ID:,项目名称:,代码行数:37,代码来源:

示例7: paintText

void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p)
{
    bool preferRichText = textFormat == Qt::RichText
                          || (textFormat == Qt::AutoText && Qt::mightBeRichText(text));

    if (!preferRichText) {
        QTextLayout textLayout;
        textLayout.setText(text);
        textLayout.setFont(font);
        textLayout.setTextOption(textOption);

        qreal leading = QFontMetricsF(font).leading();
        qreal height = -leading;

        textLayout.beginLayout();
        while (1) {
            QTextLine line = textLayout.createLine();
            if (!line.isValid())
                break;

            if (textWidth >= 0.0)
                line.setLineWidth(textWidth);
            height += leading;
            line.setPosition(QPointF(0.0, height));
            height += line.height();
        }
        textLayout.endLayout();

        actualSize = textLayout.boundingRect().size();
        textLayout.draw(p, topLeftPosition);
    } else {
        QTextDocument document;
#ifndef QT_NO_CSSPARSER
        QColor color = p->pen().color();
        document.setDefaultStyleSheet(QString::fromLatin1("body { color: #%1%2%3 }")
                                      .arg(QString::number(color.red(), 16), 2, QLatin1Char('0'))
                                      .arg(QString::number(color.green(), 16), 2, QLatin1Char('0'))
                                      .arg(QString::number(color.blue(), 16), 2, QLatin1Char('0')));
#endif
        document.setDefaultFont(font);
        document.setDocumentMargin(0.0);        
#ifndef QT_NO_TEXTHTMLPARSER
        document.setHtml(text);
#else
        document.setPlainText(text);
#endif
        if (textWidth >= 0.0)
            document.setTextWidth(textWidth);
        else
            document.adjustSize();
        document.setDefaultTextOption(textOption);

        p->save();
        p->translate(topLeftPosition);
        QAbstractTextDocumentLayout::PaintContext ctx;
        ctx.palette.setColor(QPalette::Text, p->pen().color());
        document.documentLayout()->draw(p, ctx);
        p->restore();

        if (textWidth >= 0.0)
            document.adjustSize(); // Find optimal size

        actualSize = document.size();
    }
}
开发者ID:maxxant,项目名称:qt,代码行数:65,代码来源:qstatictext.cpp

示例8: minimumSizeHint

QSize AboutLabel::minimumSizeHint() const
{
    QTextDocument *doc = document();
    doc->adjustSize();
    return QSize(int(doc->size().width()), int(doc->size().height()));
}
开发者ID:,项目名称:,代码行数:6,代码来源:

示例9: adjustSize

void QTextDocumentProto::adjustSize()
{
  QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
  if (item)
    item->adjustSize();
}
开发者ID:,项目名称:,代码行数:6,代码来源:

示例10: pm

BalloonMsg::BalloonMsg(void *param, const QString &text, QStringList &btn, QWidget *parent, const QRect *rcParent,
                       bool bModal, bool bAutoHide, unsigned bwidth, const QString &box_msg, bool *bChecked)
        : QDialog(parent,
                  (bAutoHide ? Qt::Popup : Qt::Window | Qt::WindowStaysOnTopHint)
                  | Qt::FramelessWindowHint | Qt::Tool)
        , m_check(NULL)
		, m_bAutoHide(bAutoHide)
        , m_bYes(false)
        , m_bChecked(bChecked)
        , m_param(param)
		, frm(new QFrame(this))
		, vlay(new QVBoxLayout(frm))
		, lay(new QHBoxLayout())
{
    setModal(bModal);
    setAttribute(Qt::WA_DeleteOnClose);
    setPalette(QToolTip::palette());

    bool bTailDown = true;
    //QFrame *frm = new QFrame(this);
    //QVBoxLayout *vlay = new QVBoxLayout(frm);
    vlay->setMargin(0);
    
    if (!box_msg.isEmpty()){
        m_check = new QCheckBox(box_msg, frm);
        vlay->addWidget(m_check);
        if (m_bChecked)
            m_check->setChecked(*m_bChecked);
    }
    //QHBoxLayout *lay = new QHBoxLayout();
    vlay->addLayout(lay);
    lay->setSpacing(5);
    lay->addStretch();
    unsigned id = 0;
    bool bFirst = true;
    for (QStringList::Iterator it = btn.begin(); it != btn.end(); ++it, id++){
        BalloonButton *b = new BalloonButton(*it, frm, id);
        connect(b, SIGNAL(action(int)), this, SLOT(action(int)));
        lay->addWidget(b);
        if (bFirst){
            b->setDefault(true);
            bFirst = false;
        }
    }
    //setButtonsPict(this);
    lay->addStretch();
    int hButton  = frm->minimumSizeHint().height();

    int txtWidth = bwidth;
    QRect rc;
    if (rcParent){
        rc = *rcParent;
    }else{
        QPoint p = parent->mapToGlobal(parent->rect().topLeft());
        rc = QRect(p.x(), p.y(), parent->width(), parent->height());
    }
    if (rc.width() > txtWidth)
        txtWidth = rc.width();

    QTextDocument doc;
    doc.setHtml(text);
    doc.adjustSize();
    doc.setDefaultFont(font());

    QSizeF s = doc.size();
    QSize sMin = frm->minimumSizeHint();
    if (s.width() < sMin.width())
        s.setWidth(sMin.width());
    int BALLOON_SHADOW = BALLOON_SHADOW_DEF;
    resize((int)s.width() + BALLOON_R * 2 + BALLOON_SHADOW,
           (int)s.height() + BALLOON_R * 2 + BALLOON_TAIL + BALLOON_SHADOW + hButton + BALLOON_MARGIN);
    int w = width() - BALLOON_SHADOW;
    int tailX = w / 2;
    int posX = rc.left() + rc.width() / 2 + BALLOON_TAIL_WIDTH - tailX;
    if (posX <= screenGeometry().left())
        posX = 1;
    QRect rcScreen = screenGeometry();
    if (posX + width() >= rcScreen.width())
        posX = rcScreen.width() - 1 - width();
    int tx = posX + tailX - BALLOON_TAIL_WIDTH;
    if (tx < rc.left())
        tx = rc.left();
    if (tx > rc.left() + rc.width())
        tx = rc.left() + rc.width();
    tailX = tx + BALLOON_TAIL_WIDTH - posX;
    if (tailX < BALLOON_R) tailX = BALLOON_R;
    if (tailX > width() - BALLOON_R - BALLOON_TAIL_WIDTH)
        tailX = width() - BALLOON_R - BALLOON_TAIL_WIDTH;
    if (rc.top() <= height() + 2){
        bTailDown = false;
        move(posX, rc.top() + rc.height() + 1);
    }else{
        move(posX, rc.top() - height() - 1);
    }
    int pos = 0;
    int h = height() - BALLOON_SHADOW - BALLOON_TAIL;
    if (!bTailDown)
        pos += BALLOON_TAIL;
    frm->resize((int)s.width(), hButton);
    frm->move(BALLOON_R, pos + h - BALLOON_R - hButton);
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的QTextDocument::adjustSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。