本文整理汇总了C++中QTextTable::cellAt方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextTable::cellAt方法的具体用法?C++ QTextTable::cellAt怎么用?C++ QTextTable::cellAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextTable
的用法示例。
在下文中一共展示了QTextTable::cellAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeMessage
void ChatWindow::writeMessage(MessType type, QString mess )
{
if( mess.isEmpty() ){
return;
}
QTextCursor cursor( m_chatEdit->textCursor() );
cursor.movePosition(QTextCursor::End);
QTextTable* table = cursor.insertTable(1, 2, *m_tableFormat );
QTextCharFormat charFormat;
switch( type ){
case MyMess :
charFormat.setForeground(Qt::blue);
table->cellAt(0,0).firstCursorPosition().insertText("<" + m_myName + "> ", charFormat);
table->cellAt(0,1).firstCursorPosition().insertText(mess);
break;
case ConMess :
charFormat.setForeground(Qt::darkGreen);
table->cellAt(0,0).firstCursorPosition().insertText("<" + m_conName + "> ", charFormat);
table->cellAt(0,1).firstCursorPosition().insertText(mess);
break;
case StatusMess :
charFormat.setForeground(Qt::darkRed);
cursor.insertText(" *** " + mess + " *** ", charFormat);
break;
default :
kWarning() << "Wrong MessType";
break;
}
QScrollBar *bar = m_chatEdit->verticalScrollBar();
bar->setValue(bar->maximum());
}
示例2: cursor
void
ChatDialog::appendChatMessage(const QString& nick, const QString& text, time_t timestamp)
{
QTextCharFormat nickFormat;
nickFormat.setForeground(Qt::darkGreen);
nickFormat.setFontWeight(QFont::Bold);
nickFormat.setFontUnderline(true);
nickFormat.setUnderlineColor(Qt::gray);
// Print who & when
QTextCursor cursor(ui->textEdit->textCursor());
cursor.movePosition(QTextCursor::End);
QTextTableFormat tableFormat;
tableFormat.setBorder(0);
QTextTable *table = cursor.insertTable(1, 2, tableFormat);
QString from = QString("%1 ").arg(nick);
QTextTableCell fromCell = table->cellAt(0, 0);
fromCell.setFormat(nickFormat);
fromCell.firstCursorPosition().insertText(from);
printTimeInCell(table, timestamp);
// Print what
QTextCursor nextCursor(ui->textEdit->textCursor());
nextCursor.movePosition(QTextCursor::End);
table = nextCursor.insertTable(1, 1, tableFormat);
table->cellAt(0, 0).firstCursorPosition().insertText(text);
// Popup notification
showMessage(from, text);
QScrollBar *bar = ui->textEdit->verticalScrollBar();
bar->setValue(bar->maximum());
}
示例3: 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);
}
示例4: appendMessage
void MyChat::appendMessage(const QString from, const QString message)
{
QTextCursor cursor(textEdit->textCursor());
cursor.movePosition(QTextCursor::End);
QTextTable *table = cursor.insertTable(1, 2, tableFormat);
table->cellAt(0, 0).firstCursorPosition().insertText('<' + from + ">: ");
table->cellAt(0, 1).firstCursorPosition().insertText(message);
QScrollBar *bar = textEdit->verticalScrollBar();
bar->setValue(bar->maximum());
}
示例5: buat_table
void Dialog_report::buat_table()
{
int i;
QTextCursor cursor( ui->edit->textCursor());
cursor.movePosition(QTextCursor::Start);
ui->edit->setText("Ini report");
/*
QTextTableFormat format;
format.setHeight( 600 );
format.setWidth( 800 );
format.setCellPadding( 1 );
format.setCellSpacing( 1 );
format.setHeaderRowCount( 2 );
QTextTable *table = cursor.insertTable(10, 5, format);
*/
QTextTable *table = cursor.insertTable(10, 5 );
QTextBlockFormat centerAlignment;
centerAlignment.setAlignment(Qt::AlignHCenter);
centerAlignment.setLineHeight( 30, QTextBlockFormat::FixedHeight);
centerAlignment.setLeftMargin( 10 );
centerAlignment.setRightMargin( 10 );
QTextCursor cursor2;
cursor2 = table->cellAt(0, 0).firstCursorPosition();
cursor2.insertText(QString::fromUtf8("No"));
cursor2.setBlockFormat(centerAlignment);
for (i=1; i<9; i++)
{
cursor2 = table->cellAt(i, 0).firstCursorPosition();
cursor2.setBlockFormat(centerAlignment);
cursor2.insertText(QString::number(i+1) + "Sil");
}
/*
int i, y;
for (i=0; i<4; i++)
{
for (y=0;y<5; y++)
QTextTable *table = cursor.insertTable( y, i );
//QTextTable *table = cursor.insertTable( y, i, tableFormat);
}*/
//QTextTable *tbl;
//tbl = new QTextTable( ui->edit );
}
示例6: sl_InsertColumnAction_Triggered
void TextEditWidget::sl_InsertColumnAction_Triggered() {
QTextTable* table = textField->textCursor().currentTable();
if (!table) {
WARNING("Wrong button state");
return;
}
QTextTableCell currentCell = table->cellAt(textField->textCursor());
table->insertColumns(currentCell.column() + 1, 1);
QTextTableCell cell = table->cellAt(0, currentCell.column() + 1);
textField->setTextCursor(cell.firstCursorPosition());
}
示例7: appendMessage
void ChatDialog::appendMessage(const QString &from, const QString &message)
{
if (from.isEmpty() || message.isEmpty())
return;
QTextCursor cursor(textEdit->textCursor());
cursor.movePosition(QTextCursor::End);
QTextTable *table = cursor.insertTable(1, 2, tableFormat);
table->cellAt(0, 0).firstCursorPosition().insertText("<" + from + "> ");
table->cellAt(0, 1).firstCursorPosition().insertText(message);
QScrollBar *bar = textEdit->verticalScrollBar();
bar->setValue(bar->maximum());
}
示例8: sl_RemoveColumnAction_Triggered
void TextEditWidget::sl_RemoveColumnAction_Triggered() {
QTextTable* table = textField->textCursor().currentTable();
if (!table) {
WARNING("Wrong button state");
return;
}
int columnNumber = table->cellAt(textField->textCursor()).column();
table->removeColumns(columnNumber, 1);
}
示例9: 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();
}
示例10: testFindingTables
void testFindingTables()
{
// How to find all the tables in a QTextDocument?
QTextDocument textDoc;
QTextCursor c( &textDoc );
QTextTable* firstTable = c.insertTable( 2, 2 );
QTextTableCell bottomRight = firstTable->cellAt( 1, 1 );
QTextTable* secondTable = bottomRight.firstCursorPosition().insertTable( 3, 3 ); // a nested table
c.movePosition( QTextCursor::End );
QTextTable* thirdTable = c.insertTable( 1, 1 );
thirdTable->firstCursorPosition().insertText( "in table" );
c.insertText( "Foo" );
QList<QTextTable *> origTables;
origTables << firstTable << secondTable << thirdTable;
// A generic and slow solution is
// curs.currentTable() && !tablesFound.contains(curs.currentTable())
// for each cursor position. Surely there's better.
// We could jump to currentFrame().lastCursorPosition() but then it would skip
// nested tables.
QTextDocument* clonedDoc = textDoc.clone();
QSet<QTextTable *> tablesFound;
{
QTextCursor curs(clonedDoc);
while (!curs.atEnd()) {
QTextTable* currentTable = curs.currentTable();
if ( currentTable && !tablesFound.contains(currentTable) ) {
tablesFound.insert( currentTable );
}
curs.movePosition( QTextCursor::NextCharacter );
}
QCOMPARE( tablesFound.size(), 3 );
}
// Let's do something else then, let's find them by cursor position
QList<QTextTable *> tablesByPos;
{
// first test
const int firstPos = firstTable->firstCursorPosition().position();
QTextCursor curs( clonedDoc );
curs.setPosition( firstPos );
QVERIFY( curs.currentTable() );
// generic loop. works this approach is in TextDocument::breakTables now.
Q_FOREACH( QTextTable* origTable, origTables ) {
QTextCursor curs( clonedDoc );
curs.setPosition( origTable->firstCursorPosition().position() );
tablesByPos.append( curs.currentTable() );
}
QCOMPARE( tablesByPos.size(), 3 );
QCOMPARE( tablesByPos.toSet(), tablesFound );
}
示例11: insertTable
QObject* TextCursor::insertTable(int rows, int columns)
{
QTextTableFormat format;
//format.setColumns(columns);
//format.setHeaderRowCount(1);
format.setBackground(QColor("#e0e0e0"));
//format.setCellPadding(1); format.setCellSpacing(1); //testcase
QVector<QTextLength> constraints;
constraints << QTextLength(QTextLength::PercentageLength, 16);
constraints << QTextLength(QTextLength::PercentageLength, 28);
constraints << QTextLength(QTextLength::PercentageLength, 28);
constraints << QTextLength(QTextLength::PercentageLength, 28);
format.setColumnWidthConstraints(constraints);
QTextTable* table = m_cursor.insertTable(rows, columns, format);
//QTextTable* t = m_cursor.insertTable(rows, columns);
QTextTableCell cell = table->cellAt(0, 0);
cell.firstCursorPosition().insertText(tr("aaa") /*, QTextCharFormat::charFormat*/);
table->cellAt(0, 1).firstCursorPosition().insertText(tr("bbb"));
return new TextTable(this, table);
}
示例12: onTableAddRowClicked
// Добавление строк в таблицу
void TableFormatter::onTableAddRowClicked(void)
{
QTextCursor cursor(textArea->textCursor());
QTextTable *table = cursor.currentTable();
if(table)
{
QTextTableCell cell=table->cellAt(cursor); // Выясняется текущая ячейка
int cellRowCursor=cell.row(); // Текущий номер строки (счет с нуля)
bool ok=false;
int addNum=QInputDialog::getInt(editor, tr("Append rows to table"),tr("Append rows:"), 1, 1, 100, 1, &ok);
if(ok && addNum > 0)
table->insertRows(cellRowCursor + 1,addNum);
}
}
示例13: printTreeWidget
void DashboardWindow::printTreeWidget(QPrinter *printer) {
//build a table
QTextDocument doc;
QTextCursor cursor(&doc);
QTextTable *table = cursor.insertTable(1, ui.treeWidget->columnCount());
//header
for (int colNum = 0; colNum < ui.treeWidget->columnCount(); ++colNum) {
table->cellAt(0, colNum).firstCursorPosition().insertText(ui.treeWidget->headerItem()->text(colNum));
}
//table content
treeWidgetToTextTable(ui.treeWidget->invisibleRootItem(), table, 1);
doc.print(printer);
}
示例14: insertSampleTable
void TestChangeTrackedDelete::insertSampleTable(QTextDocument *document)
{
QTextCursor cursor(document);
cursor.insertText("This is a paragraph of text before a table.");
QTextTable *table = cursor.insertTable(3,3);
table->cellAt(0,0).firstCursorPosition().insertText("first");
table->cellAt(0,1).firstCursorPosition().insertText("second");
table->cellAt(0,2).firstCursorPosition().insertText("third");
table->cellAt(1,0).firstCursorPosition().insertText("fourth");
table->cellAt(1,1).firstCursorPosition().insertText("fifth");
table->cellAt(1,2).firstCursorPosition().insertText("sixth");
table->cellAt(2,0).firstCursorPosition().insertText("seventh");
table->cellAt(2,1).firstCursorPosition().insertText("eigth");
table->cellAt(2,2).firstCursorPosition().insertText("ninth");
}
示例15: addFrameDecorations
void QQuickTextNodeEngine::addFrameDecorations(QTextDocument *document, QTextFrame *frame)
{
QTextDocumentLayout *documentLayout = qobject_cast<QTextDocumentLayout *>(document->documentLayout());
QTextFrameFormat frameFormat = frame->format().toFrameFormat();
QTextTable *table = qobject_cast<QTextTable *>(frame);
QRectF boundingRect = table == 0
? documentLayout->frameBoundingRect(frame)
: documentLayout->tableBoundingRect(table);
QBrush bg = frame->frameFormat().background();
if (bg.style() != Qt::NoBrush)
m_backgrounds.append(qMakePair(boundingRect, bg.color()));
if (!frameFormat.hasProperty(QTextFormat::FrameBorder))
return;
qreal borderWidth = frameFormat.border();
if (qFuzzyIsNull(borderWidth))
return;
QBrush borderBrush = frameFormat.borderBrush();
QTextFrameFormat::BorderStyle borderStyle = frameFormat.borderStyle();
if (borderStyle == QTextFrameFormat::BorderStyle_None)
return;
addBorder(boundingRect.adjusted(frameFormat.leftMargin(), frameFormat.topMargin(),
-frameFormat.rightMargin(), -frameFormat.bottomMargin()),
borderWidth, borderStyle, borderBrush);
if (table != 0) {
int rows = table->rows();
int columns = table->columns();
for (int row=0; row<rows; ++row) {
for (int column=0; column<columns; ++column) {
QTextTableCell cell = table->cellAt(row, column);
QRectF cellRect = documentLayout->tableCellBoundingRect(table, cell);
addBorder(cellRect.adjusted(-borderWidth, -borderWidth, 0, 0), borderWidth,
borderStyle, borderBrush);
}
}
}
}