本文整理汇总了C++中QTextTableFormat::setCellPadding方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextTableFormat::setCellPadding方法的具体用法?C++ QTextTableFormat::setCellPadding怎么用?C++ QTextTableFormat::setCellPadding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextTableFormat
的用法示例。
在下文中一共展示了QTextTableFormat::setCellPadding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printDeckListNode
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
{
static const int totalColumns = 3;
if (node->height() == 1) {
QTextBlockFormat blockFormat;
QTextCharFormat charFormat;
charFormat.setFontPointSize(11);
charFormat.setFontWeight(QFont::Bold);
cursor->insertBlock(blockFormat, charFormat);
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)));
QTextTableFormat tableFormat;
tableFormat.setCellPadding(0);
tableFormat.setCellSpacing(0);
tableFormat.setBorder(0);
QTextTable *table = cursor->insertTable(node->size() + 1, 2, tableFormat);
for (int i = 0; i < node->size(); i++) {
AbstractDecklistCardNode *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
QTextCharFormat cellCharFormat;
cellCharFormat.setFontPointSize(9);
QTextTableCell cell = table->cellAt(i, 0);
cell.setFormat(cellCharFormat);
QTextCursor cellCursor = cell.firstCursorPosition();
cellCursor.insertText(QString("%1 ").arg(card->getNumber()));
cell = table->cellAt(i, 1);
cell.setFormat(cellCharFormat);
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(card->getName());
}
} else if (node->height() == 2) {
QTextBlockFormat blockFormat;
QTextCharFormat charFormat;
charFormat.setFontPointSize(14);
charFormat.setFontWeight(QFont::Bold);
cursor->insertBlock(blockFormat, charFormat);
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)));
QTextTableFormat tableFormat;
tableFormat.setCellPadding(10);
tableFormat.setCellSpacing(0);
tableFormat.setBorder(0);
QVector<QTextLength> constraints;
for (int i = 0; i < totalColumns; i++)
constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns);
tableFormat.setColumnWidthConstraints(constraints);
QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat);
for (int i = 0; i < node->size(); i++) {
QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition();
printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
}
}
cursor->movePosition(QTextCursor::End);
}
示例2: onCreatetableClicked
// Действия при нажатии кнопки создания новой таблицы
void TableFormatter::onCreatetableClicked(void)
{
// Создается и запускается диалог создания новой таблицы
EditorAddTableForm dialog;
if(dialog.exec()!=QDialog::Accepted) return;
// Выясняются введенные в диалоге данные
int tableColumns=dialog.get_columns();
int tableRows=dialog.get_rows();
int tableWidth=dialog.get_width();
// Целочислительный формат ширины таблицы преобразуется в проценты
QTextLength tableWidthInPercent(QTextLength::PercentageLength, tableWidth);
// Создается форматирование таблицы
QTextTableFormat tableFormat;
tableFormat.setWidth(tableWidthInPercent);
tableFormat.setAlignment(Qt::AlignHCenter);
tableFormat.setBorder(1);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
tableFormat.setPadding(0);
tableFormat.setCellPadding(0);
tableFormat.setCellSpacing(-1);
// Добавляется таблица с нужными размерами и форматированием
// QTextTable *table=textarea->textCursor().insertTable(table_rows, table_columns, table_format);
textArea->textCursor().insertTable(tableRows, tableColumns, tableFormat);
return;
}
示例3: QTextEdit
/*!
* \author Anders Fernström
* \date 2005-12-19
*
* \brief The class constructor
*
* 2006-03-03 AF, Updated function so cells are printed in tables,
* so chapter numbers can be added to the left of the text. This
* change remade large part of this function (and the rest of the
* class).
*/
PrinterVisitor::PrinterVisitor( QTextDocument* doc, QPrinter* printer )
: ignore_(false), firstChild_(true), closedCell_(0), currentTableRow_(0), printer_(printer)
{
printEditor_ = new QTextEdit();
printEditor_->setDocument( doc );
// set table format
QTextTableFormat tableFormat;
tableFormat.setBorder( 0 );
tableFormat.setColumns( 2 );
tableFormat.setCellPadding( 2 );
// do not put the constraints on the columns. If we don't have chapter numbers we want to use the full space.
// QVector<QTextLength> constraints;
// constraints << QTextLength(QTextLength::PercentageLength, 20)
// << QTextLength(QTextLength::PercentageLength, 80);
// tableFormat.setColumnWidthConstraints(constraints);
// insert the table
QTextCursor cursor = printEditor_->textCursor();
table_ = cursor.insertTable(1, 2, tableFormat);
}
示例4: visitTextCellNodeBefore
// TEXTCELL
void PrinterVisitor::visitTextCellNodeBefore(TextCell *node)
{
if( !ignore_ || firstChild_ )
{
++currentTableRow_;
table_->insertRows( currentTableRow_, 1 );
// first column
QTextTableCell tableCell( table_->cellAt( currentTableRow_, 0 ) );
if( tableCell.isValid() )
{
if( !node->ChapterCounterHtml().isNull() )
{
QTextCursor cursor( tableCell.firstCursorPosition() );
cursor.insertFragment( QTextDocumentFragment::fromHtml(
node->ChapterCounterHtml() ));
}
}
// second column
tableCell = table_->cellAt( currentTableRow_, 1 );
if( tableCell.isValid() )
{
QTextCursor cursor( tableCell.firstCursorPosition() );
if( node->isViewExpression() )
{
//view expression table
QTextTableFormat tableFormatExpression;
tableFormatExpression.setBorder( 0 );
tableFormatExpression.setColumns( 1 );
tableFormatExpression.setCellPadding( 2 );
// tableFormatExpression.setBackground( QColor(235, 235, 220) ); // 180, 180, 180
tableFormatExpression.setBackground( QColor(235, 0, 0) ); // 180, 180, 180
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 100);
tableFormatExpression.setColumnWidthConstraints(constraints);
cursor.insertTable( 1, 1, tableFormatExpression );
// QMessageBox::information(0,"uu2", node->text());
QString html = node->textHtml();
cursor.insertFragment( QTextDocumentFragment::fromHtml( html ));
}
else
{
QString html = node->textHtml();
html.remove( "file:///" );
printEditor_->document()->setTextWidth(700);
cursor.insertFragment(QTextDocumentFragment::fromHtml( html ));
// QMessageBox::information(0, "uu3", node->text());
}
}
if( firstChild_ )
firstChild_ = false;
}
}
示例5: on_insertTable_clicked
void MainWindow::on_insertTable_clicked()
{
InsertTableDialog dlg;
if(dlg.exec() != QDialog::Accepted)
return;
QTextEdit *pEdit = textEditor.editor;
QTextCursor cursor = pEdit->textCursor();
QTextTableFormat format;
format.setCellSpacing(0);
format.setCellPadding(5);
cursor.insertTable(dlg.row(), dlg.column(), format);
pEdit->setFocus();
}
示例6: newLetter
//! [2]
void MainWindow::newLetter()
{
textEdit->clear();
QTextCursor cursor(textEdit->textCursor());
cursor.movePosition(QTextCursor::Start);
QTextFrame *topFrame = cursor.currentFrame();
QTextFrameFormat topFrameFormat = topFrame->frameFormat();
topFrameFormat.setPadding(16);
topFrame->setFrameFormat(topFrameFormat);
QTextCharFormat textFormat;
QTextCharFormat boldFormat;
boldFormat.setFontWeight(QFont::Bold);
QTextCharFormat italicFormat;
italicFormat.setFontItalic(true);
QTextTableFormat tableFormat;
tableFormat.setBorder(1);
tableFormat.setCellPadding(16);
tableFormat.setAlignment(Qt::AlignRight);
cursor.insertTable(1, 1, tableFormat);
cursor.insertText("The Firm", boldFormat);
cursor.insertBlock();
cursor.insertText("321 City Street", textFormat);
cursor.insertBlock();
cursor.insertText("Industry Park");
cursor.insertBlock();
cursor.insertText("Some Country");
cursor.setPosition(topFrame->lastPosition());
cursor.insertText(QDate::currentDate().toString("d MMMM yyyy"), textFormat);
cursor.insertBlock();
cursor.insertBlock();
cursor.insertText("Dear ", textFormat);
cursor.insertText("NAME", italicFormat);
cursor.insertText(",", textFormat);
for (int i = 0; i < 3; ++i)
cursor.insertBlock();
cursor.insertText(tr("Yours sincerely,"), textFormat);
for (int i = 0; i < 3; ++i)
cursor.insertBlock();
cursor.insertText("The Boss", textFormat);
cursor.insertBlock();
cursor.insertText("ADDRESS", italicFormat);
}
示例7: main
int main(int argc, char * argv[])
{
int rows = 6;
int columns = 2;
QApplication app(argc, argv);
QTextEdit *textEdit = new QTextEdit;
QTextCursor cursor(textEdit->textCursor());
cursor.movePosition(QTextCursor::Start);
QTextTableFormat tableFormat;
tableFormat.setAlignment(Qt::AlignHCenter);
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(2);
QTextTable *table = cursor.insertTable(rows, columns);
table->setFormat(tableFormat);
QTextCharFormat boldFormat;
boldFormat.setFontWeight(QFont::Bold);
QTextBlockFormat centerFormat;
centerFormat.setAlignment(Qt::AlignHCenter);
cursor.mergeBlockFormat(centerFormat);
cursor = table->cellAt(0, 0).firstCursorPosition();
cursor.insertText(("Details"), boldFormat);
cursor = table->cellAt(1, 0).firstCursorPosition();
cursor.insertText("Alan");
cursor = table->cellAt(1, 1).firstCursorPosition();
cursor.insertText("5, Pickety Street");
//! [0]
table->mergeCells(0, 0, 1, 2);
//! [0] //! [1]
table->splitCell(0, 0, 1, 1);
//! [1]
textEdit->show();
return app.exec();
}
示例8: cursor
void KDReports::TextDocumentData::scaleFontsBy( qreal factor )
{
QTextCursor cursor( m_document );
qreal currentPointSize = -1.0;
QTextCursor lastCursor( m_document );
Q_FOREVER {
qreal cursorFontPointSize = cursor.charFormat().fontPointSize();
//qDebug() << cursorFontPointSize << "last=" << currentPointSize << cursor.block().text() << "position=" << cursor.position();
if ( cursorFontPointSize != currentPointSize ) {
if ( currentPointSize != -1.0 ) {
setFontSizeHelper( lastCursor, cursor.position() - 1, currentPointSize, factor );
lastCursor.setPosition( cursor.position() - 1, QTextCursor::MoveAnchor );
}
currentPointSize = cursorFontPointSize;
}
if ( cursor.atEnd() )
break;
cursor.movePosition( QTextCursor::NextCharacter );
}
if ( currentPointSize != -1.0 ) {
setFontSizeHelper( lastCursor, cursor.position(), currentPointSize, factor );
}
// Also adjust the padding in the cells so that it remains proportional,
// and the column constraints.
Q_FOREACH( QTextTable* table, m_tables ) {
QTextTableFormat format = table->format();
format.setCellPadding( format.cellPadding() * factor );
QVector<QTextLength> constraints = format.columnWidthConstraints();
for ( int i = 0; i < constraints.size(); ++i ) {
if ( constraints[i].type() == QTextLength::FixedLength ) {
constraints[i] = QTextLength( QTextLength::FixedLength, constraints[i].rawValue() * factor );
}
}
format.setColumnWidthConstraints( constraints );
table->setFormat( format );
}
示例9: QTextLength
void KDReports::AbstractTableElement::fillTableFormat( QTextTableFormat& tableFormat, QTextCursor& textDocCursor ) const
{
if ( d->m_width ) {
if ( d->m_unit == Millimeters ) {
tableFormat.setWidth( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_width ) ) );
} else {
tableFormat.setWidth( QTextLength( QTextLength::PercentageLength, d->m_width ) );
}
}
tableFormat.setBorder( border() );
#if QT_VERSION >= 0x040300
tableFormat.setBorderBrush( borderBrush() );
tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid );
#endif
tableFormat.setCellPadding( mmToPixels( padding() ) );
tableFormat.setCellSpacing( -1 ); // HTML-like table borders look so old century
if ( d->m_fontSpecified ) {
QTextCharFormat charFormat = textDocCursor.charFormat();
charFormat.setFont( d->m_defaultFont );
textDocCursor.setCharFormat( charFormat );
}
}
示例10: sl_CreateTableAction_Triggered
void TextEditWidget::sl_CreateTableAction_Triggered() {
QTextTable* table = textField->textCursor().currentTable();
if (table) {
return;
}
textField->textCursor().beginEditBlock();
table = textField->textCursor().insertTable(2, 2);
QTextTableFormat format = table->format();
format.setCellSpacing(0);
format.setCellPadding(3);
format.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
QTextLength tableWidth(QTextLength::PercentageLength, 50);
format.setWidth(tableWidth);
table->setFormat(format);
textField->textCursor().endEditBlock();
QTextTableCell cell = table->cellAt(0, 0);
textField->setTextCursor(cell.firstCursorPosition());
}
示例11: QTextEdit
/*!
* \author Anders Fernström
* \date 2005-12-19
*
* \brief The class constructor
*
* 2006-03-03 AF, Updated function so cells are printed in tables,
* so chapter numbers can be added to the left of the text. This
* change remade large part of this function (and the rest of the
* class).
*/
PrinterVisitor::PrinterVisitor( QTextDocument* doc, QPrinter* printer )
: ignore_(false), firstChild_(true), closedCell_(0), currentTableRow_(0), printer_(printer)
{
printEditor_ = new QTextEdit();
printEditor_->setDocument( doc );
// set table format
QTextTableFormat tableFormat;
tableFormat.setBorder( 0 );
tableFormat.setColumns( 2 );
tableFormat.setCellPadding( 5 );
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::FixedLength, 50)
<< QTextLength(QTextLength::VariableLength, 620);
tableFormat.setColumnWidthConstraints(constraints);
// insert the table
QTextCursor cursor = printEditor_->textCursor();
table_ = cursor.insertTable(1, 2, tableFormat);
}
示例12: uri
/** "Help message" or "About" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
QDialog(parent),
ui(new Ui::HelpMessageDialog)
{
ui->setupUi(this);
QString version = tr("Beardcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
/* On x86 add a bit specifier to the version so that users can distinguish between
* 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
*/
#if defined(__x86_64__)
version += " " + tr("(%1-bit)").arg(64);
#elif defined(__i386__ )
version += " " + tr("(%1-bit)").arg(32);
#endif
if (about)
{
setWindowTitle(tr("About Beardcoin Core"));
/// HTML-format the license message from the core
QString licenseInfo = QString::fromStdString(LicenseInfo());
QString licenseInfoHTML = licenseInfo;
// Make URLs clickable
QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
uri.setMinimal(true); // use non-greedy matching
licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
// Replace newlines with HTML breaks
licenseInfoHTML.replace("\n\n", "<br><br>");
ui->aboutMessage->setTextFormat(Qt::RichText);
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
text = version + "\n" + licenseInfo;
ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
ui->aboutMessage->setWordWrap(true);
ui->helpMessage->setVisible(false);
} else {
setWindowTitle(tr("Command-line options"));
QString header = tr("Usage:") + "\n" +
" beardcoin-qt [" + tr("command-line options") + "] " + "\n";
QTextCursor cursor(ui->helpMessage->document());
cursor.insertText(version);
cursor.insertBlock();
cursor.insertText(header);
cursor.insertBlock();
QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT));
text = version + "\n" + header + "\n" + coreOptions;
QTextTableFormat tf;
tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
tf.setCellPadding(2);
QVector<QTextLength> widths;
widths << QTextLength(QTextLength::PercentageLength, 35);
widths << QTextLength(QTextLength::PercentageLength, 65);
tf.setColumnWidthConstraints(widths);
QTextCharFormat bold;
bold.setFontWeight(QFont::Bold);
Q_FOREACH (const QString &line, coreOptions.split("\n")) {
if (line.startsWith(" -"))
{
cursor.currentTable()->appendRows(1);
cursor.movePosition(QTextCursor::PreviousCell);
cursor.movePosition(QTextCursor::NextRow);
cursor.insertText(line.trimmed());
cursor.movePosition(QTextCursor::NextCell);
} else if (line.startsWith(" ")) {
cursor.insertText(line.trimmed()+' ');
} else if (line.size() > 0) {
//Title of a group
if (cursor.currentTable())
cursor.currentTable()->appendRows(1);
cursor.movePosition(QTextCursor::Down);
cursor.insertText(line.trimmed(), bold);
cursor.insertTable(1, 2, tf);
}
}
ui->helpMessage->moveCursor(QTextCursor::Start);
ui->scrollArea->setVisible(false);
ui->aboutLogo->setVisible(false);
}
}
示例13: createPages
void KWQTableView::createPages(QPrinter *printer, QTextDocument *textDoc, bool sendToPrinter)
{
printer->setFullPage(true);
int myDpi = printer->logicalDpiY();
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Flashcard) {
printer->setOrientation(QPrinter::Landscape);
int cardWidth = qRound(5 * qreal(myDpi));
int cardHeight = qRound(3 * qreal(myDpi));
QTextTable *table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount(), 2);
QTextTableFormat tableFormat = table->format();
tableFormat.setHeaderRowCount(0);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
tableFormat.setCellSpacing(0);
tableFormat.setCellPadding(0);
QVector<QTextLength> constraints;
constraints.append(QTextLength(QTextLength::FixedLength, cardWidth));
constraints.append(QTextLength(QTextLength::FixedLength, cardWidth));
tableFormat.setColumnWidthConstraints(constraints);
table->setFormat(tableFormat);
QTextBlockFormat headerFormat;
headerFormat.setAlignment(Qt::AlignLeft);
QTextCharFormat headerCharFormat;
headerCharFormat.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
QTextBlockFormat cellFormat;
cellFormat.setAlignment(Qt::AlignCenter);
QTextCharFormat cellCharFormat;
cellCharFormat.setFont(Prefs::editorFont());
QTextFrameFormat cardFormat;
cardFormat.setBorder(1);
cardFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
cardFormat.setBorderBrush(QBrush(Qt::black));
cardFormat.setWidth(QTextLength(QTextLength::FixedLength, cardWidth));
cardFormat.setHeight(QTextLength(QTextLength::FixedLength, cardHeight));
cardFormat.setPadding(qRound(0.25 * myDpi));
QTextFrameFormat lineFormat;
lineFormat.setBorder(1);
lineFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
lineFormat.setBorderBrush(QBrush(Qt::black));
lineFormat.setWidth(QTextLength(QTextLength::FixedLength, qRound(4.5 * myDpi)));
lineFormat.setHeight(1.1); //1 is drawn as a box whereas this is drawn as a line. Strange...
lineFormat.setPadding(0);
QTextFrame *card;
for (int i = 0; i < model()->rowCount(); i++) {
for (int j = 0; j < model()->columnCount(); j++) {
cardFormat.setPosition(QTextFrameFormat::FloatLeft);
card = table->cellAt(i, j).firstCursorPosition().insertFrame(cardFormat);
card->lastCursorPosition().insertText(model()->headerData(j, Qt::Horizontal, Qt::DisplayRole).toString(), headerCharFormat);
card->lastCursorPosition().insertFrame(lineFormat);
card->lastCursorPosition().insertBlock();
card->lastCursorPosition().insertBlock();
card->lastCursorPosition().insertBlock(cellFormat, cellCharFormat);
card->lastCursorPosition().insertText(model()->data(model()->index(i, j)).toString(), cellCharFormat);
}
}
}
else
{
textDoc->rootFrame()->lastCursorPosition().insertText(QStringLiteral("kwordquiz %1").arg(KWQ_VERSION));
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
textDoc->rootFrame()->lastCursorPosition().insertText(' ' + i18n("Name:_____________________________ Date:__________"));
QTextTable* table;
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount() + 1, model()->columnCount() + 2);
else
table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount() + 1, model()->columnCount() + 1);
QTextTableFormat tableFormat = table->format();
tableFormat.setHeaderRowCount(1);
tableFormat.setBorder(1);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
tableFormat.setCellSpacing(0);
tableFormat.setBorderBrush(QBrush(Qt::black));
tableFormat.setCellPadding(2);
QVector<QTextLength> constraints;
constraints.append(QTextLength(QTextLength::FixedLength, verticalHeader()->width()));
constraints.append(QTextLength(QTextLength::FixedLength, columnWidth(0)));
constraints.append(QTextLength(QTextLength::FixedLength, columnWidth(1)));
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
constraints.append(QTextLength(QTextLength::FixedLength, 50));
tableFormat.setColumnWidthConstraints(constraints);
table->setFormat(tableFormat);
QTextBlockFormat headerFormat;
//.........这里部分代码省略.........
示例14: writeTable
bool OutputQtDocument::writeTable()
{
/*
start of table
*/
m_cursor.beginEditBlock();
m_cursor.insertBlock();
m_cursor.insertBlock();
QTextFrame *topFrame = m_cursor.currentFrame();
QTextTableFormat tableFormat;
tableFormat.setCellPadding(4);
tableFormat.setHeaderRowCount(1);
/* tableFormat.setBorderStyle(
QTextFrameFormat::BorderStyle_Double); */
tableFormat.setMargin(2);
tableFormat.setWidth(QTextLength(
QTextLength::PercentageLength, 100));
QTextTable *table = m_cursor.insertTable(
m_params->height()+2, m_params->width()+5, tableFormat);
/*
headers
*/
m_cursor = table->cellAt(0, 0).firstCursorPosition();
m_cursor.insertText("i");
m_cursor = table->cellAt(0, 1).firstCursorPosition();
m_cursor.insertText(tr("basis"));
m_cursor = table->cellAt(0, 2).firstCursorPosition();
m_cursor.insertHtml("C<sub>i</sub> ");
m_cursor = table->cellAt(0, 3).firstCursorPosition();
m_cursor.insertText("B");
for(size_t j=0; j < m_params->width(); j++)
{
m_cursor = table->cellAt(0, j+4).firstCursorPosition();
m_cursor.insertHtml(QString("P<sub>%1</sub> ").arg(j+1));
/* m_cursor.insertHtml(QString("C<sub>%1</sub> =").arg(j+1));
if(m_params->variableType(j) == SimplexMethod::VariableArtificial)
m_cursor.insertText("W");
else
m_cursor.insertText(formatDouble(m_params->rowC(j))); */
}
m_cursor = table->cellAt(0, m_params->width()+4).firstCursorPosition();
m_cursor.insertText(QChar(0x0398)); // theta
/*
matrix, columnCompareOp, columnB, columnTheta
*/
for(size_t i=0; i < m_params->height(); i++)
{
m_cursor = table->cellAt(i+1, 0).firstCursorPosition();
m_cursor.insertText(QString("%1").arg(i+1));
// basis
m_cursor = table->cellAt(i+1, 1).firstCursorPosition();
size_t basisColumn = m_params->columnBasis(i);
m_cursor.insertHtml(QString("P<sub>%1</sub> ").arg(basisColumn+1));
// basis C
m_cursor = table->cellAt(i+1, 2).firstCursorPosition();
if(m_params->variableType(basisColumn) == SimplexMethod::VariableArtificial)
m_cursor.insertText("W");
else
m_cursor.insertText(formatDouble(m_params->rowC(basisColumn)));
// B
m_cursor = table->cellAt(i+1, 3).firstCursorPosition();
m_cursor.insertText(formatDouble(m_params->columnB(i)));
// matrix
for(size_t j=0; j < m_params->width(); j++)
{
m_cursor = table->cellAt(i+1, j+4).firstCursorPosition();
m_cursor.insertText(formatDouble(m_params->matrixA(i, j)));
}
// theta
m_cursor = table->cellAt(i+1, m_params->width()+4).firstCursorPosition();
if(m_params->columnTheta(i) > 0)
m_cursor.insertText(formatDouble(m_params->columnTheta(i)));
else
m_cursor.insertText("-");
}
/*
m+1 row
*/
m_cursor = table->cellAt(m_params->height()+1, 0).firstCursorPosition();
m_cursor.insertText("m+1");
m_cursor = table->cellAt(m_params->height()+1, 3).firstCursorPosition();
m_cursor.insertText(formatDouble(m_params->F()));
for(size_t j=0; j < m_params->width(); j++)
{
m_cursor = table->cellAt(m_params->height()+1, j+4).firstCursorPosition();
//.........这里部分代码省略.........
示例15:
QTextTable * PrintDialog::insertCategoryTable(QTextCursor & cursor, const QString & categoryName)
{
QTextBlockFormat blockCategoryTitleFormat;
blockCategoryTitleFormat.setAlignment(Qt::AlignCenter);
blockCategoryTitleFormat.setTopMargin(40.0);
blockCategoryTitleFormat.setBottomMargin(30.0);
QTextCharFormat categoryTitleFormat;
categoryTitleFormat.setFontCapitalization(QFont::AllUppercase);
categoryTitleFormat.setFontWeight(25);
categoryTitleFormat.setFontPointSize(14.0);
QString category = "Category \"";
category += categoryName;
category += "\"";
cursor.insertBlock(blockCategoryTitleFormat);
cursor.insertText(category,categoryTitleFormat);
cursor.insertBlock(QTextBlockFormat()); // to break the previous block format
QTextTable * table = cursor.insertTable(1, 4);
if(!table)
return NULL;
QTextTableFormat categoryTableFormat;
categoryTableFormat.setAlignment(Qt::AlignHCenter);
categoryTableFormat.setHeaderRowCount(1); // header line
categoryTableFormat.setBorderStyle(QTextTableFormat::BorderStyle_Solid);
categoryTableFormat.setBorder(1.0);
categoryTableFormat.setCellPadding(10);
categoryTableFormat.setCellSpacing(0);
table->setFormat(categoryTableFormat);
// header :
// header cell format :
QTextCharFormat headerCellFormat;
headerCellFormat.setFontWeight(50);
headerCellFormat.setFontPointSize(12.0);
headerCellFormat.setBackground(QBrush(QColor(60,60,60)));
headerCellFormat.setForeground(QBrush(QColor(255,255,255)));
QTextTableCell cell = table->cellAt(0,0);
cell.setFormat(headerCellFormat);
cursor = cell.firstCursorPosition();
cursor.insertText(tr("Position"));
cell = table->cellAt(0,1);
cell.setFormat(headerCellFormat);
cursor = cell.firstCursorPosition();
cursor.insertText(tr("LastName"));
cell = table->cellAt(0,2);
cell.setFormat(headerCellFormat);
cursor = cell.firstCursorPosition();
cursor.insertText(tr("Firstname"));
cell = table->cellAt(0,3);
cell.setFormat(headerCellFormat);
cursor = cell.firstCursorPosition();
cursor.insertText(tr("Time"));
return table;
}