#include <QDebug>
#include <QVBoxLayout>
#include <QTextEdit>
#include <QPushButton>
#include <QTextTable>
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
lay->addWidget(edit);
changeTable
= new QPushButton ( trUtf8
("Change table") );
connect( changeTable, SIGNAL( clicked(bool) ), SLOT( SlotChangeTable() ) );
lay->addWidget(changeTable);
setCentralWidget(w);
// addTable
tableFormat.setAlignment(Qt::AlignCenter);
tableFormat.setCellPadding( 4 );
tableFormat.setCellSpacing( 0 );
edit->textCursor().insertTable(3, 7, tableFormat);
cursor.setPosition(1);
edit->setTextCursor(cursor);
QTextTable* table
= edit
->textCursor
().
currentTable();
table->mergeCells( 0, 0, 2 , 1);
table->mergeCells( 0, 1, 2 , 1);
table->mergeCells( 0, 2, 2 , 1);
table->mergeCells( 0, 3, 2 , 1);
table->mergeCells( 0, 5, 2 , 1);
table->mergeCells( 0, 6, 2 , 1);
table->mergeCells( 2, 0, 1, 6);
}
MainWindow::~MainWindow()
{
}
void MainWindow::SlotChangeTable()
{
QTextTable* table
= edit
->textCursor
().
currentTable();
qDebug() << table->columns();
table->insertColumns(1,1);
}
#include <QDebug>
#include <QVBoxLayout>
#include <QTextEdit>
#include <QPushButton>
#include <QTextTable>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QWidget* w = new QWidget(this);
QVBoxLayout* lay = new QVBoxLayout(w);
edit = new QTextEdit(this);
lay->addWidget(edit);
QPushButton* changeTable;
changeTable = new QPushButton ( trUtf8("Change table") );
connect( changeTable, SIGNAL( clicked(bool) ), SLOT( SlotChangeTable() ) );
lay->addWidget(changeTable);
setCentralWidget(w);
// addTable
QTextTableFormat tableFormat;
tableFormat.setAlignment(Qt::AlignCenter);
tableFormat.setBorderStyle( QTextTableFormat::BorderStyle_Solid );
tableFormat.setCellPadding( 4 );
tableFormat.setCellSpacing( 0 );
tableFormat.setWidth( QTextLength( QTextLength::PercentageLength, 100 ) );
edit->textCursor().insertTable(3, 7, tableFormat);
QTextCursor cursor(edit->textCursor());
cursor.setPosition(1);
edit->setTextCursor(cursor);
QTextTable* table = edit->textCursor().currentTable();
table->mergeCells( 0, 0, 2 , 1);
table->mergeCells( 0, 1, 2 , 1);
table->mergeCells( 0, 2, 2 , 1);
table->mergeCells( 0, 3, 2 , 1);
table->mergeCells( 0, 5, 2 , 1);
table->mergeCells( 0, 6, 2 , 1);
table->mergeCells( 2, 0, 1, 6);
}
MainWindow::~MainWindow()
{
}
void MainWindow::SlotChangeTable()
{
QTextTable* table = edit->textCursor().currentTable();
qDebug() << table->columns();
table->insertColumns(1,1);
}
To copy to clipboard, switch view to plain text mode
Bookmarks