Hi, why insertColumns() dont'work in this example?
Qt Code:
  1. #include <QDebug>
  2. #include <QVBoxLayout>
  3. #include <QTextEdit>
  4. #include <QPushButton>
  5. #include <QTextTable>
  6. #include "mainwindow.h"
  7.  
  8. MainWindow::MainWindow(QWidget *parent)
  9. : QMainWindow(parent)
  10. {
  11. QWidget* w = new QWidget(this);
  12.  
  13. QVBoxLayout* lay = new QVBoxLayout(w);
  14. edit = new QTextEdit(this);
  15. lay->addWidget(edit);
  16. QPushButton* changeTable;
  17. changeTable = new QPushButton ( trUtf8("Change table") );
  18. connect( changeTable, SIGNAL( clicked(bool) ), SLOT( SlotChangeTable() ) );
  19. lay->addWidget(changeTable);
  20.  
  21. setCentralWidget(w);
  22.  
  23.  
  24. // addTable
  25. QTextTableFormat tableFormat;
  26. tableFormat.setAlignment(Qt::AlignCenter);
  27. tableFormat.setBorderStyle( QTextTableFormat::BorderStyle_Solid );
  28. tableFormat.setCellPadding( 4 );
  29. tableFormat.setCellSpacing( 0 );
  30. tableFormat.setWidth( QTextLength( QTextLength::PercentageLength, 100 ) );
  31.  
  32. edit->textCursor().insertTable(3, 7, tableFormat);
  33.  
  34. QTextCursor cursor(edit->textCursor());
  35. cursor.setPosition(1);
  36. edit->setTextCursor(cursor);
  37.  
  38. QTextTable* table = edit->textCursor().currentTable();
  39. table->mergeCells( 0, 0, 2 , 1);
  40.  
  41. table->mergeCells( 0, 1, 2 , 1);
  42. table->mergeCells( 0, 2, 2 , 1);
  43. table->mergeCells( 0, 3, 2 , 1);
  44. table->mergeCells( 0, 5, 2 , 1);
  45. table->mergeCells( 0, 6, 2 , 1);
  46. table->mergeCells( 2, 0, 1, 6);
  47.  
  48. }
  49.  
  50. MainWindow::~MainWindow()
  51. {
  52.  
  53. }
  54.  
  55. void MainWindow::SlotChangeTable()
  56. {
  57. QTextTable* table = edit->textCursor().currentTable();
  58. qDebug() << table->columns();
  59. table->insertColumns(1,1);
  60. }
To copy to clipboard, switch view to plain text mode