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


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

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


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

示例1: rc

void
DelegateHelper::render_html2( QPainter * painter, const QStyleOptionViewItem& option, const QString& text )
{
    auto op = option;
    
    painter->save();

    QTextDocument document;

    document.setDefaultTextOption( QTextOption( Qt::AlignVCenter ) ); // hit to QTBUG 13467 -- valign is not taking in account ??
    document.setDefaultFont( op.font );
    document.setDefaultStyleSheet( "{ vertical-align: middle; }" );
    document.setHtml( text );

    op.displayAlignment |= Qt::AlignVCenter;
    op.text = "";
    op.widget->style()->drawControl( QStyle::CE_ItemViewItem, &op, painter, op.widget );

    QRect cbx = op.widget->style()->subElementRect( QStyle::SE_CheckBoxIndicator, &option, op.widget );
    QRect rc( option.rect );
    rc.setLeft( cbx.right() + 4 );

    painter->translate( cbx.right() + 4, option.rect.top() ); // workaround for VCenter
    document.drawContents( painter ); // rc.translated( -rc.topLeft() ) );

    painter->restore();
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2: QTextOption

void
DelegateHelper::render_html( QPainter * painter, const QStyleOptionViewItem& option, const QString& text, const QString& css )
{
    painter->save();

    auto op = option;
    QTextDocument document;

    if ( !css.isEmpty() ) {
        document.setDefaultStyleSheet( css );
    } else {
        document.setDefaultTextOption( QTextOption( op.displayAlignment ) ); // QTBUG 13467 -- valign is not taking in account
        document.setDefaultFont( op.font );
    }
    document.setHtml( QString("<body>%1</body>").arg( text ) );

    op.displayAlignment |= Qt::AlignVCenter;
    op.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();
}
开发者ID:,项目名称:,代码行数:25,代码来源:

示例3: paintSection

 void paintSection( QPainter * painter, const QRect& rect, int logicalIndex ) const override {
     
     if ( rect.isValid() ) {
         if ( logicalIndex > 0 ) {
             QStyleOptionHeader op;
             initStyleOption(&op);
             op.text = "";
             op.rect = rect;
             op.textAlignment = Qt::AlignVCenter | Qt::AlignHCenter;
             // draw the section
             style()->drawControl( QStyle::CE_Header, &op, painter, this );
             // html painting
             painter->save();
             QRect textRect = style()->subElementRect( QStyle::SE_HeaderLabel, &op, this );
             painter->translate( textRect.topLeft() );
             QTextDocument doc;
             doc.setTextWidth( textRect.width() );
             doc.setDefaultTextOption( QTextOption( Qt::AlignHCenter ) );
             doc.setDocumentMargin(0);
             doc.setHtml( model()->headerData( logicalIndex, Qt::Horizontal ).toString() );
             doc.drawContents( painter, QRect( QPoint( 0, 0 ), textRect.size() ) );
             painter->restore();
         } else {
             QHeaderView::paintSection( painter, rect, logicalIndex );
         }
     }
 }
开发者ID:hermixy,项目名称:qtplatz,代码行数:27,代码来源:htmlheaderview.hpp

示例4: ensureTextLayouted

void QLabelPrivate::ensureTextLayouted() const
{
    if (!textLayoutDirty)
        return;
    ensureTextPopulated();
    if (control) {
        QTextDocument *doc = control->document();
        QTextOption opt = doc->defaultTextOption();

        opt.setAlignment(QFlag(this->align));

        if (this->align & Qt::TextWordWrap)
            opt.setWrapMode(QTextOption::WordWrap);
        else
            opt.setWrapMode(QTextOption::ManualWrap);

        doc->setDefaultTextOption(opt);

        QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
        fmt.setMargin(0);
        doc->rootFrame()->setFrameFormat(fmt);
        doc->setTextWidth(documentRect().width());
    }
    textLayoutDirty = false;
}
开发者ID:,项目名称:,代码行数:25,代码来源:

示例5: QSize

//static
QSize
DelegateHelper::html_size_hint( const QStyleOptionViewItem& option, const QModelIndex& index )
{
    QTextDocument document;
	document.setDefaultTextOption( QTextOption( option.displayAlignment ) );
	document.setDefaultFont( option.font );
    document.setHtml( index.data().toString() );
    return QSize( document.size().width(), document.size().height() );  
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例6: setShowWhitespace

void GenericCodeEditor::setShowWhitespace(bool show)
{
    QTextDocument *doc = textDocument();
    QTextOption opt( doc->defaultTextOption() );
    if( show )
        opt.setFlags( opt.flags() | QTextOption::ShowTabsAndSpaces );
    else
        opt.setFlags( opt.flags() & ~QTextOption::ShowTabsAndSpaces );
    doc->setDefaultTextOption(opt);
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:10,代码来源:editor.cpp

示例7: setUpDisplayDoc

void setUpDisplayDoc(QTextDocument& displayDoc, const QFont font){
    QTextOption to;
    //to.setWrapMode(QTextOption::NoWrap);
    to.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    displayDoc.setDefaultTextOption(to);

    displayDoc.setDefaultFont(font);
    displayDoc.setDocumentMargin(0); //default is 4!
    displayDoc.setIndentWidth(0);
    displayDoc.setDefaultStyleSheet( UI_LIST_LINE_DEFAULT_STYLE);

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

示例8: drawStandBy_

void DanmakuMove::drawStandBy_(){

	if (startPaintDMIndex_ <= dmCreater_->totalDMCount_) {
		return;
	}

	if (!isNeedUpdateStandBy_)
		return;
	else
		isNeedUpdateStandBy_ = false;

	QFont font;
	font.setBold(true);
	font.setFamily(QString("Microsoft YaHei"));
	font.setPixelSize(25);

	QString styleStr = QString(
		"<p>"
		"<span style = \" font-size:%1px; color:#FF9DCB; \">%2< / span>"
		"</p>");
	QString standByStr = styleStr.arg(font.pixelSize()).arg(tr("Stand By"));

	QTextDocument td;
	td.setDefaultFont(font);
	td.setDocumentMargin(10);

	QTextOption op = td.defaultTextOption();
	op.setAlignment(Qt::AlignHCenter);
	td.setDefaultTextOption( op );
	td.setHtml(standByStr);
	td.setTextWidth(dmSideWidSize_.width());
	QSize s = td.size().toSize();

	if (standByPix_)
		delete standByPix_;
	standByPix_ = new QPixmap(QSize(dmSideWidSize_.width(), 60));
	standByPix_->fill(Qt::transparent);
	QPainter p(standByPix_);
	p.setPen(QPen(QColor(0x49545A)));
	p.setBrush(QBrush(QColor(0x49545A), Qt::SolidPattern));
	p.setFont(font);

	int border = 1;
	QRect r(0, 0, standByPix_->width(), standByPix_->height());
	p.setOpacity(0.6);
	p.drawRoundedRect(r.adjusted(border, border, -border, -border), 3, 3);

	td.drawContents(&p);

	dmSideWidBKPixCache_->fill(Qt::transparent);
	QPainter pSideDM(dmSideWidBKPixCache_);
	pSideDM.drawPixmap(QPoint(0, dmSideWidBKPixCache_->height()-standByPix_->height()+border), *standByPix_);
}
开发者ID:dourgulf,项目名称:biliobs,代码行数:53,代码来源:danmakumove.cpp

示例9: main

int main(int argc, char *argv[]) {
  QApplication app(argc, argv);

  if (argc != 2) {
    fprintf(stderr, "Usage: runcible-open-ext-txt <file>");
    return 1;
  }

  QString filename(argv[1]);
  QFile file(filename);
  QString suffix(QFileInfo(file).suffix());

  qDebug() << "Loading" << filename;
  QString text;
  if (file.open(QIODevice::ReadOnly)) {
    qDebug() << "Opened";
    text = file.readAll();
    qDebug() << "Loaded";
  }


  RWindow window;
  PageView display;
  window.layout()->addWidget(&display);
  qDebug() << "Added display.";

  QObject::connect(&display, SIGNAL(pageCountChanged(int)), &window, SLOT(showTimeline(int)));
  QObject::connect(&display, SIGNAL(pageChanged(int)), &window, SLOT(updateTimeline(int)));

  window.showMaximized();

  QTextDocument doc;
  doc.setDefaultTextOption(QTextOption(Qt::AlignJustify));
  doc.setMetaInformation(QTextDocument::DocumentUrl, QUrl::fromLocalFile(filename).toString());
  if (suffix == "html") {
    doc.setHtml(text);
  } else {
    text.replace(QRegExp("([^\\r\\n])(\\r)?\\n([^\\n\\r])"), "\\1  \\3");
    doc.setPlainText(text);
  }
  qDebug() << "Created doc.";
  display.setDocument(filename, &doc);
  qDebug() << "Set doc.";

  QObject::connect(&window, SIGNAL(back()), &app, SLOT(quit()));

  window.showMessage(doc.metaInformation(QTextDocument::DocumentTitle));

  return app.exec();
}
开发者ID:cbiffle,项目名称:runcible,代码行数:50,代码来源:main.cpp

示例10: setFlag

GraphicsTextItem::GraphicsTextItem(){
    setFlag(QGraphicsItem::ItemIsMovable);
    setFlag(QGraphicsItem::ItemIsSelectable);
    setFlag(QGraphicsItem::ItemIsFocusable);
    setAcceptDrops(true);
    setAcceptHoverEvents(true);


    QTextDocument *tdocument =  document();
    tdocument->setModified(true);
    QTextOption option = tdocument->defaultTextOption();
    option.setAlignment(Qt::AlignHCenter);
    tdocument->setDefaultTextOption(option);
    //setTextWidth(tdocument->idealWidth());
    setTextWidth(400);

}
开发者ID:ginozh,项目名称:my_wmm,代码行数:17,代码来源:mainwindow.cpp

示例11: 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();
            }
开发者ID:hermixy,项目名称:qtplatz,代码行数:18,代码来源:proteintable.cpp

示例12: 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

示例13: styleSheet

SimpleRichTextEdit::SimpleRichTextEdit(QWidget *parent)
	: KTextEdit(parent)
{
	enableFindReplace(false);
	setCheckSpellingEnabled(true);

	setAutoFormatting(KTextEdit::AutoNone);
	setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

	QTextDocument *textDocument = document();

	QTextOption textOption;
	textOption.setAlignment(Qt::AlignCenter);
	textOption.setWrapMode(QTextOption::NoWrap);
	textDocument->setDefaultTextOption(textOption);

	QFont defaultFont = font();
	defaultFont.setPointSize(defaultFont.pointSize() + 2);
	textDocument->setDefaultFont(defaultFont);

	QString styleSheet("p {" "   display: block;" "   white-space: pre;" "   margin-top: 0px;" "   margin-bottom: 0px;" "}");
	textDocument->setDefaultStyleSheet(styleSheet);

	setTextInteractionFlags(Qt::TextEditorInteraction);

	m_actions[Undo] = new QAction(this);
	m_actions[Undo]->setIcon(QIcon::fromTheme("edit-undo"));
	m_actions[Undo]->setText(i18n("Undo"));
	m_actions[Undo]->setShortcuts(KStandardShortcut::undo());
	connect(m_actions[Undo], SIGNAL(triggered()), this, SLOT(undo()));

	m_actions[Redo] = new QAction(this);
	m_actions[Redo]->setIcon(QIcon::fromTheme("edit-redo"));
	m_actions[Redo]->setText(i18n("Redo"));
	m_actions[Redo]->setShortcuts(KStandardShortcut::redo());
	connect(m_actions[Redo], SIGNAL(triggered()), this, SLOT(redo()));

	m_actions[Cut] = new QAction(this);
	m_actions[Cut]->setIcon(QIcon::fromTheme("edit-cut"));
	m_actions[Cut]->setText(i18n("Cut"));
	m_actions[Cut]->setShortcuts(KStandardShortcut::cut());
	connect(m_actions[Cut], SIGNAL(triggered()), this, SLOT(cut()));

	m_actions[Copy] = new QAction(this);
	m_actions[Copy]->setIcon(QIcon::fromTheme("edit-copy"));
	m_actions[Copy]->setText(i18n("Copy"));
	m_actions[Copy]->setShortcuts(KStandardShortcut::copy());
	connect(m_actions[Copy], SIGNAL(triggered()), this, SLOT(copy()));

#if !defined(QT_NO_CLIPBOARD)
	m_actions[Paste] = new QAction(this);
	m_actions[Paste]->setIcon(QIcon::fromTheme("edit-paste"));
	m_actions[Paste]->setText(i18n("Paste"));
	m_actions[Paste]->setShortcuts(KStandardShortcut::paste());
	connect(m_actions[Paste], SIGNAL(triggered()), this, SLOT(paste()));
#endif

	m_actions[Delete] = new QAction(this);
	m_actions[Delete]->setIcon(QIcon::fromTheme("edit-delete"));
	m_actions[Delete]->setText(i18n("Delete"));
	m_actions[Delete]->setShortcut(QKeySequence::Delete);
	connect(m_actions[Delete], SIGNAL(triggered()), this, SLOT(deleteText()));

	m_actions[Clear] = new QAction(this);
	m_actions[Clear]->setIcon(QIcon::fromTheme("edit-clear"));
	m_actions[Clear]->setText(i18nc("@action:inmenu Clear all text", "Clear"));
	connect(m_actions[Clear], SIGNAL(triggered()), this, SLOT(undoableClear()));

	m_actions[SelectAll] = new QAction(this);
	m_actions[SelectAll]->setIcon(QIcon::fromTheme("edit-select-all"));
	m_actions[SelectAll]->setText(i18n("Select All"));
	m_actions[SelectAll]->setShortcut(QKeySequence::SelectAll);
	connect(m_actions[SelectAll], SIGNAL(triggered()), this, SLOT(selectAll()));

	m_actions[ToggleBold] = new QAction(this);
	m_actions[ToggleBold]->setIcon(QIcon::fromTheme("format-text-bold"));
	m_actions[ToggleBold]->setText(i18nc("@action:inmenu Toggle bold style", "Bold"));
	m_actions[ToggleBold]->setShortcut(QKeySequence("Ctrl+B"));
	connect(m_actions[ToggleBold], SIGNAL(triggered()), this, SLOT(toggleFontBold()));

	m_actions[ToggleItalic] = new QAction(this);
	m_actions[ToggleItalic]->setIcon(QIcon::fromTheme("format-text-italic"));
	m_actions[ToggleItalic]->setText(i18nc("@action:inmenu Toggle italic style", "Italic"));
	m_actions[ToggleItalic]->setShortcut(QKeySequence("Ctrl+I"));
	connect(m_actions[ToggleItalic], SIGNAL(triggered()), this, SLOT(toggleFontItalic()));

	m_actions[ToggleUnderline] = new QAction(this);
	m_actions[ToggleUnderline]->setIcon(QIcon::fromTheme("format-text-underline"));
	m_actions[ToggleUnderline]->setText(i18nc("@action:inmenu Toggle underline style", "Underline"));
	m_actions[ToggleUnderline]->setShortcut(QKeySequence("Ctrl+U"));
	connect(m_actions[ToggleUnderline], SIGNAL(triggered()), this, SLOT(toggleFontUnderline()));

	m_actions[ToggleStrikeOut] = new QAction(this);
	m_actions[ToggleStrikeOut]->setIcon(QIcon::fromTheme("format-text-strikethrough"));
	m_actions[ToggleStrikeOut]->setText(i18nc("@action:inmenu Toggle strike through style", "Strike Through"));
	m_actions[ToggleStrikeOut]->setShortcut(QKeySequence("Ctrl+T"));
	connect(m_actions[ToggleStrikeOut], SIGNAL(triggered()), this, SLOT(toggleFontStrikeOut()));

	m_actions[ChangeTextColor] = new QAction(this);
	m_actions[ChangeTextColor]->setIcon(QIcon::fromTheme("format-text-color"));
//.........这里部分代码省略.........
开发者ID:maxrd2,项目名称:subtitlecomposer,代码行数:101,代码来源:simplerichtextedit.cpp

示例14: DrawResults


//.........这里部分代码省略.........
    auto DrawRowLeft = [ &painter, &free_rect ]( QFont font, QColor color1, QString label, double spase = 1 )
    {
        painter.save();
        QFontMetrics metrix( font );
        QRect place;
        AllocatePlace( place, metrix.height()*spase, free_rect );
        QPoint start_point( place.left() , place.center().y()+metrix.height()/2 );
        painter.setFont( font );
        painter.setPen( color1 );
        painter.drawText( start_point, label );
        painter.restore();
    };

    auto DrawRowLeft3 = [ &painter, &free_rect ](    QFont const& font,
                                                    QColor const& color1,
                                                    QString const& label,
                                                    QColor const& color2 = Qt::black,
                                                    QString const& value = "",
                                                    QColor const& color3 = Qt::black,
                                                    QString const& value2 = "",
                                                    double spase = 1)
    {
        painter.save();
        QFontMetrics metrix( font );
        QRect place;
        AllocatePlace( place, metrix.height()*spase, free_rect );
        QPoint start_point( place.left() , place.center().y()+metrix.height()/2 );
        QPoint start_point2( start_point.x() + metrix.width(label), place.center().y() +metrix.height()/2);
        QPoint start_point3( start_point2.x() + metrix.width(value), place.center().y() +metrix.height()/2);
        painter.setFont( font );
        painter.setPen( color1 );
        painter.drawText( start_point, label );
        painter.setPen( color2 );
        painter.drawText( start_point2, value );
        painter.setPen( color3 );
        painter.drawText( start_point3, value2 );
        painter.restore();
    };

    DrawRowCenter( title_font, Qt::black, "", 7 );
    DrawRowCenter( title_font, Qt::black, "Результаты испытаний", 1 );
    DrawRowCenter2( title_font, Qt::black, "дискретного аппарата ", Qt::red, mGsType, 2 );

    QString header = "<html>"
            "<head>"
              "<meta charset='utf-8'>"
              "<style type='text/css'>"
                   "td { text-align: center;}"
                   "th { font-weight: normal; padding: 2px;}"
                   "table {border-collapse: collapse; border-style: solid; vertical-align:middle;}"
             "</style>"
            "</head>"
            "<body>"
            "<table width='100%' border='1.5' cellspacing='-0.5' cellpadding='-0.5'>"
               "<tr>"
                   "<th> Номер </th>"
                   "<th></th>"
                   "<th> Работоспособность </th>"
               "</tr>";

    QString footer = "</table>"
            "</body>"
            "</html>";

    bool sucsess = true;

    QString row;
    for ( auto it =  mTestCase.begin(), end = mTestCase.end(); it != end; ++it )
    {
        Test* ptr = *it;
        row +=  "<tr>"
                   "<td>"+test::ToString( ptr->Number() )+"</td>"
                   "<td>"+ QString(ptr->Name()).replace("\n","<br>") +"</td>"
                   "<td style='font-size:28pt; color: \"red\"; font-weight:bold;'>"+ (ptr->Success() ? QString("+"):QString("-")) +"</td>"
                "</tr>";
        sucsess &= ptr->Success();
    }

    QTextDocument doc;
    doc.setUndoRedoEnabled( false );
    doc.setTextWidth( free_rect.width() );
    doc.setUseDesignMetrics( true );
    doc.setDefaultTextOption ( QTextOption (Qt::AlignHCenter )  );
    doc.setHtml( header + row + footer );
    auto h = doc.documentLayout()->documentSize().height();

    QRect place;
    AllocatePlace( place, h ,free_rect );
    QRectF r( 0, 0, place.width(), place.height() );
    painter.save();
    painter.translate( place.topLeft() );
    doc.drawContents( &painter, r);
    painter.restore();

    DrawRowLeft( text_font, Qt::black, "ИТОГ:", 3 );
    DrawRowLeft3( text_font, Qt::black, "Гидроаппарат ",
                            Qt::red, mGsType + (sucsess? " годен": " не годен"),
                            Qt::black, " к эксплуатации", 1 );
    return true;
}
开发者ID:firef0xff,项目名称:SSHGS01,代码行数:101,代码来源:test_params_hydro.cpp

示例15: Draw


//.........这里部分代码省略.........
    int width = m.width("123456789012345678901234567890123456789012345");
    char symbol = '.';
    auto FillToSize = [ width, &m, symbol ]( QString text )
    {
        while( m.width( text + symbol ) < width )
            text += symbol;
        return text + " ";
    };


    uint32_t num = 0;
    bool res = DrawLine( num, free_rect, result_font,
    [ this, &painter, &DrawRowCenter, &result_font ]( QRect const& rect )
    {
        DrawRowCenter( rect, result_font, Qt::black, "Результаты испытаний" );
    }, 2 );

    res = DrawLine( num, free_rect, text_font,
    [ this, &painter, &DrawRowLeft, &FillToSize, &text_font ]( QRect const& rect )
    {
        DrawRowLeft( rect, text_font, Qt::black, FillToSize("Температура масла во время испытаний, ˚С"), Qt::red, test::ToString(OilTemp) );
    }, 2 );


    QString header = "<html>"
            "<head>"
              "<meta charset='utf-8'>"
              "<style type='text/css'>"
                   "td { text-align: center;}"
                   "th { font-weight: normal; padding: 2px;}"
                   "table {border-collapse: collapse; border-style: solid; vertical-align:middle;}"
             "</style>"
            "</head>"
            "<body>"
            "<table width='100%' border='1.5' cellspacing='-0.5' cellpadding='-0.5'>"
               "<tr>"
                   "<th> Номер </th>"
                   "<th></th>"
                   "<th> Работоспособность </th>"
               "</tr>";

    QString footer = "</table>"
            "</body>"
            "</html>";

    typedef std::pair<QString, bool> Item;
    std::vector< Item > tests;
    tests.push_back( Item( "Наружная герметичность ", HermResult ) );
    tests.push_back( Item( "Максимальное давление", MaxPressureResult ) );
    tests.push_back( Item( "Рабочее давление", WorkPressureResult ) );
    tests.push_back( Item( "Номинальный расход", ExpenditureResult ) );
    tests.push_back( Item( "Время перемещения в одну сторону", MoveTimeResult ) );

    QString rows;
    for ( size_t i =  1, end = tests.size(); i <= end; ++i )
    {
        Item& data = tests[i-1];
        rows +=  "<tr>"
                   "<td>"+test::ToString( static_cast<int>(i) )+"</td>"
                   "<td>"+ data.first +"</td>"
                   "<td style='font-size:28pt; color: \"red\"; font-weight:bold;'>"+ (data.second ? QString("+"):QString("-")) +"</td>"
                "</tr>";
    }

    QString table = header + rows + footer;


    QTextDocument doc;
    doc.setUndoRedoEnabled( false );
    doc.setTextWidth( free_rect.width() );
    doc.setUseDesignMetrics( true );
    doc.setDefaultTextOption ( QTextOption (Qt::AlignHCenter )  );
    doc.setHtml( table );
    auto h = doc.documentLayout()->documentSize().height();

    res = DrawLine( num, free_rect, text_font,
    [ this, &painter, &doc, &text_font ]( QRect const& rect )
    {
        painter.save();
        QRectF r( 0, 0, rect.width(), rect.height() );
        painter.translate( rect.topLeft() );
        doc.drawContents( &painter, r);
        painter.restore();
    }, 1, h );

    res = DrawLine( num, free_rect, header_font,
    [ this, &painter, &DrawRowLeft, &header_font ]( QRect const& rect )
    {
        DrawRowLeft( rect, header_font, Qt::black, "ИТОГ:" );
    }, 1.5 );

    res = DrawLine( num, free_rect, text_font,
    [ this, &painter, &DrawRowLeft, &text_font, params ]( QRect const& rect )
    {
        DrawRowLeft( rect, text_font,   Qt::black, "Гидроцилиндр ",
                                        Qt::red, params->SerNo() + (Success()? QString(" годен ") : QString(" не годен ")),
                                        Qt::black, " к эксплуатации");
    }, 3 );
    return res;
}
开发者ID:firef0xff,项目名称:SSHGS01,代码行数:101,代码来源:cylinder_test.cpp


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