本文整理汇总了C++中QTextTableFormat::setAlignment方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextTableFormat::setAlignment方法的具体用法?C++ QTextTableFormat::setAlignment怎么用?C++ QTextTableFormat::setAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextTableFormat
的用法示例。
在下文中一共展示了QTextTableFormat::setAlignment方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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();
}
示例4: insertCalendar
//! [5]
void MainWindow::insertCalendar()
{
editor->clear();
QTextCursor cursor = editor->textCursor();
cursor.beginEditBlock();
QDate date(selectedDate.year(), selectedDate.month(), 1);
//! [5]
//! [6]
QTextTableFormat tableFormat;
tableFormat.setAlignment(Qt::AlignHCenter);
tableFormat.setBackground(QColor("#e0e0e0"));
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(4);
//! [6] //! [7]
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14)
<< QTextLength(QTextLength::PercentageLength, 14);
tableFormat.setColumnWidthConstraints(constraints);
//! [7]
//! [8]
QTextTable *table = cursor.insertTable(1, 7, tableFormat);
//! [8]
//! [9]
QTextFrame *frame = cursor.currentFrame();
QTextFrameFormat frameFormat = frame->frameFormat();
frameFormat.setBorder(1);
frame->setFrameFormat(frameFormat);
//! [9]
//! [10]
QTextCharFormat format = cursor.charFormat();
format.setFontPointSize(fontSize);
QTextCharFormat boldFormat = format;
boldFormat.setFontWeight(QFont::Bold);
QTextCharFormat highlightedFormat = boldFormat;
highlightedFormat.setBackground(Qt::yellow);
//! [10]
//! [11]
for (int weekDay = 1; weekDay <= 7; ++weekDay) {
QTextTableCell cell = table->cellAt(0, weekDay-1);
//! [11] //! [12]
QTextCursor cellCursor = cell.firstCursorPosition();
cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)),
boldFormat);
}
//! [12]
//! [13]
table->insertRows(table->rows(), 1);
//! [13]
while (date.month() == selectedDate.month()) {
int weekDay = date.dayOfWeek();
QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1);
QTextCursor cellCursor = cell.firstCursorPosition();
if (date == QDate::currentDate())
cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat);
else
cellCursor.insertText(QString("%1").arg(date.day()), format);
date = date.addDays(1);
if (weekDay == 7 && date.month() == selectedDate.month())
table->insertRows(table->rows(), 1);
}
cursor.endEditBlock();
//! [14]
setWindowTitle(tr("Calendar for %1 %2"
).arg(QDate::longMonthName(selectedDate.month())
).arg(selectedDate.year()));
}
示例5: fillTableFormat
void KDReports::AutoTableElement::build( ReportBuilder& builder ) const
{
if( !d->m_tableModel ) {
return;
}
QTextDocument& textDoc = builder.currentDocument();
QTextCursor& textDocCursor = builder.cursor();
textDocCursor.beginEditBlock();
QTextTableFormat tableFormat;
const int headerRowCount = d->m_horizontalHeaderVisible ? 1 : 0;
const int headerColumnCount = d->m_verticalHeaderVisible ? 1 : 0;
tableFormat.setHeaderRowCount( headerRowCount );
tableFormat.setProperty( KDReports::HeaderColumnsProperty, headerColumnCount );
tableFormat.setAlignment( textDocCursor.blockFormat().alignment() );
fillTableFormat( tableFormat, textDocCursor );
while (d->m_tableModel->canFetchMore(QModelIndex()))
d->m_tableModel->fetchMore(QModelIndex());
const int rows = d->m_tableModel->rowCount();
const int columns = d->m_tableModel->columnCount();
QTextTable* textTable = textDocCursor.insertTable( rows + headerRowCount,
columns + headerColumnCount,
tableFormat );
QTextCharFormat tableHeaderFormat;
tableHeaderFormat.setBackground( d->m_headerBackground );
//qDebug( "rows = %d, columns = %d", textTable->rows(), textTable->columns() );
if( d->m_horizontalHeaderVisible ) {
for( int column = 0; column < columns; column++ ) {
QTextTableCell cell = textTable->cellAt( 0, column + headerColumnCount );
Q_ASSERT( cell.isValid() );
cell.setFormat( tableHeaderFormat );
d->fillCellFromHeaderData( column, Qt::Horizontal, cell, textDoc, textTable, builder );
}
}
if( d->m_verticalHeaderVisible ) {
for( int row = 0; row < rows; row++ ) {
QTextTableCell cell = textTable->cellAt( row + headerRowCount, 0 );
Q_ASSERT( cell.isValid() );
cell.setFormat( tableHeaderFormat );
d->fillCellFromHeaderData( row, Qt::Vertical, cell, textDoc, textTable, builder );
}
}
QVector<QBitArray> coveredCells;
coveredCells.resize(rows);
for( int row = 0; row < rows; row++ )
coveredCells[row].resize(columns);
// The normal data
for( int row = 0; row < rows; row++ ) {
for( int column = 0; column < columns; column++ ) {
if (coveredCells[row].testBit(column))
continue;
QTextTableCell cell = textTable->cellAt( row + headerRowCount, column + headerColumnCount );
Q_ASSERT( cell.isValid() );
const QSize span = d->fillTableCell( row, column, cell, textDoc, textTable, builder );
if (span.isValid()) {
for (int r = row; r < row + span.height() && r < rows; ++r) {
for (int c = column; c < column + span.width() && c < columns; ++c) {
coveredCells[r].setBit(c);
}
}
}
}
}
textDocCursor.movePosition( QTextCursor::End );
textDocCursor.endEditBlock();
builder.currentDocumentData().registerAutoTable( textTable, this );
}
示例6:
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;
}
示例7: printCalc
void CalcFrame::printCalc()
{
const auto milkReception = m_mainWindow->database()->milkReception();
if (!milkReception) {
Utils::Main::showMsgIfDbNotChoosed(this);
return;
}
DataWorker dw(m_mainWindow->database());
try {
dw.loadMilkReceptions(getWhereQuery());
} catch (const QString &err) {
QMessageBox::critical(this, tr("Расчеты"), tr("Произошла ошибка во время подгрузки данных: ") + err);
}
const auto deliverers = dw.getDeliverers().values();
if (deliverers.isEmpty())
{
QMessageBox::information(this, tr("Печать"), tr("Отсутствуют данные для печати"));
return;
}
const char f = 'f';
int row = 0;
const auto settings = m_mainWindow->getSettings();
const auto printColumns = m_mainWindow->getSettings()->getPrint().columns;
QStringList columns;
for (int i = 0; i < printColumns.size(); ++i) {
const auto &col = printColumns[i];
if (col.isShow)
columns.append(printColumns[i].display);
}
const int columnsCount = columns.size();
if (columnsCount <= 0) {
QMessageBox::information(this, tr("Печать сдачи молока"), tr("Не выбрана ни одна колонка для печати"));
return;
}
const Settings::Column snCol = printColumns[Constants::PrintColumns::SerialNumber],
delivNameCol = printColumns[Constants::PrintColumns::DeliverersName],
litersCol = printColumns[Constants::PrintColumns::Liters],
fatCol = printColumns[Constants::PrintColumns::Fat],
proteinCol = printColumns[Constants::PrintColumns::Protein],
fatUnitsCol = printColumns[Constants::PrintColumns::FatUnits],
rankWeightCol = printColumns[Constants::PrintColumns::RankWeight],
payCol = printColumns[Constants::PrintColumns::PayWithOutPrem],
permiumCol = printColumns[Constants::PrintColumns::Premium],
sumCol = printColumns[Constants::PrintColumns::Sum],
signCol = printColumns[Constants::PrintColumns::Sign];
auto itemToPrintRow = [&](const QString &delivName, const CalculatedItem::Data &item,
const int rowPos = -1) -> QStringList
{
QStringList row;
if (snCol.isShow)
row.append(rowPos >= 0 ? QString::number(rowPos) : QString());
if (delivNameCol.isShow)
row.append(delivName);
if (litersCol.isShow)
row.append(QString::number(item.liters, f, litersCol.prec));
if (fatCol.isShow)
row.append(QString::number(item.fat, f, fatCol.prec));
if (proteinCol.isShow)
row.append(QString::number(item.protein, f, proteinCol.prec));
if (fatUnitsCol.isShow)
row.append(QString::number(item.fatUnits, f, fatCol.prec));
if (rankWeightCol.isShow)
row.append(QString::number(item.rankWeight, f, rankWeightCol.prec));
if (payCol.isShow)
row.append(QString::number(item.paymentWithOutPremium, f, payCol.prec));
if (permiumCol.isShow)
row.append(QString::number(item.premiumForFat, f, permiumCol.prec));
if (sumCol.isShow)
row.append(QString::number(floor(item.sum), f, sumCol.prec));
if (signCol.isShow)
row.append(QString());
return row;
};
const auto &printSettings = settings->getPrint();
QTextTableFormat tableFormat;
tableFormat.setBorder(printSettings.tableBorderWidth);
tableFormat.setBorderStyle(static_cast<QTextFrameFormat::BorderStyle>(printSettings.tableBorderStyle));
tableFormat.setColumns(columnsCount);
tableFormat.setAlignment(Qt::AlignHCenter);
tableFormat.setWidth(QTextLength(QTextLength::VariableLength, 100));
tableFormat.setBorderBrush(QBrush(printSettings.tableBorderColor));
tableFormat.setCellSpacing(printSettings.cellSpacing);
tableFormat.setCellPadding(printSettings.cellPadding);
PrintTable print(columnsCount, tableFormat);
{
auto &textFormat = print.getTableBodyTextFormat();
textFormat.setFont(printSettings.tableTextFont);
textFormat.setForeground(QBrush(printSettings.tableTextColor));
//.........这里部分代码省略.........