I have tried this. But it doesn't work.
Qt Code:
  1. QVector<QTextLength> columnWidth;
  2. for(int i=0; i<15; i++)
  3. {
  4. if(i==0)
  5. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength,174));
  6. if(i>0 && i<10)
  7. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 42.25));
  8. else if(i>9 && i<12)
  9. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 118));
  10. else if(i==12 || i==14)
  11. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 100));
  12. else if(i==13)
  13. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 70));
  14. }
  15.  
  16. QTextTableFormat numberTableFormat;
  17. numberTableFormat.setBorder(0);
  18. numberTableFormat.setCellSpacing(-1);
  19. numberTableFormat.setColumnWidthConstraints(columnWidth);
  20. QBrush brush(Qt::black);
  21. numberTableFormat.setBorderBrush(brush);
  22. numberTableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
  23. //UPDATE
  24. numberTableFormat.setWidth(824.25);
  25.  
  26. QTextTable *mainTable = cursor.insertTable(32, 15, numberTableFormat);
  27. //SECOND OPTION:
  28. //mainTable->format().setWidth(824.25);
  29. cursor = mainTable->cellAt(0,2).firstCursorPosition();
  30. QTextFrameFormat tempFormat = cursor.currentFrame()->frameFormat();
  31. tempFormat.setBorder(1);
  32. cursor.insertFrame(tempFormat);
  33. cursor.insertText("1");
To copy to clipboard, switch view to plain text mode