本文整理汇总了C++中QTextTable类的典型用法代码示例。如果您正苦于以下问题:C++ QTextTable类的具体用法?C++ QTextTable怎么用?C++ QTextTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTextTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
示例2: Py_INCREF
static PyObject *meth_QTextTable_removeColumns(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
int a0;
int a1;
QTextTable *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "Bii", &sipSelf, sipType_QTextTable, &sipCpp, &a0, &a1))
{
Py_BEGIN_ALLOW_THREADS
sipCpp->removeColumns(a0,a1);
Py_END_ALLOW_THREADS
Py_INCREF(Py_None);
return Py_None;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QTextTable, sipName_removeColumns, doc_QTextTable_removeColumns);
return NULL;
}
示例3: cursor
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());
}
示例4: fillFrameIterator
void TextDocumentModel::fillFrameIterator(const QTextFrame::iterator &it, QStandardItem *parent)
{
if (QTextFrame *frame = it.currentFrame()) {
const QRectF b = m_document->documentLayout()->frameBoundingRect(frame);
QTextTable *table = qobject_cast<QTextTable *>(frame);
auto item = new QStandardItem;
if (table) {
item->setText(tr("Table"));
appendRow(parent, item, table->format(), b);
fillTable(table, item);
} else {
item->setText(tr("Frame"));
appendRow(parent, item, frame->frameFormat(), b);
fillFrame(frame, item);
}
}
const QTextBlock block = it.currentBlock();
if (block.isValid()) {
auto item = new QStandardItem;
item->setText(tr("Block: %1").arg(block.text()));
const QRectF b = m_document->documentLayout()->blockBoundingRect(block);
appendRow(parent, item, block.blockFormat(), b);
fillBlock(block, item);
}
}
示例5: if
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);
}
示例6: sl_MergeCellsAction_Triggered
void TextEditWidget::sl_MergeCellsAction_Triggered() {
QTextTable* table = textField->textCursor().currentTable();
if (!table) {
WARNING("Wrong button state");
return;
}
table->mergeCells(textField->textCursor());
}
示例7: 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);
}
示例8: cursor
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());
}
示例9: cursor
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 );
}
示例10: WARNING
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());
}
示例11: 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 );
}
示例12: cursor
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());
}
示例13: cursor
// Добавление строк в таблицу
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);
}
}
示例14: cursor
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);
}
示例15: addBorder
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);
}
}
}
}