Note that there are some explanatory texts on larger screens.

plurals
  1. POQTextCursor insertText not working
    text
    copied!<p>I'm trying to make a table in QT using QTextTable. The first row working fine when I set background and text but the second row is only applying the formating but the insertText function doesn't seem to work for me. I've also tried insertHTML but nothing seems to work for me on row2.</p> <pre><code>QTextTableFormat channelBankFormat; channelBankFormat.setAlignment(Qt::AlignHCenter); //channelBankFormat.setHeight(8); channelBankFormat.setColumnWidthConstraints(constraints); channelBankFormat.setBorder(0); ChannelBank-&gt;clear(); QTextCursor cursor = ChannelBank-&gt;textCursor(); cursor.beginEditBlock(); QTextTable *table = cursor.insertTable(2, 5, channelBankFormat); QTextCharFormat headerFormat = cursor.charFormat(); headerFormat.setFontWeight(QFont::Bold); headerFormat.setFontPointSize(8); QTextCharFormat dataFormat = cursor.charFormat(); dataFormat.setFontPointSize(12); QTextBlockFormat centerAlignment; centerAlignment.setAlignment(Qt::AlignCenter); for (int cellNumber = 1; cellNumber &lt;= 5; ++cellNumber) { QTextTableCell cell = table-&gt;cellAt(0, cellNumber-1); QTextCharFormat headerCellFormat = cell.format(); QTextCursor cellCursor = cell.firstCursorPosition(); headerCellFormat.setBackground(QColor(0 + (cellNumber * 50), 222, 222, 127)); cell.setFormat(headerCellFormat); cellCursor.clearSelection(); cellCursor.insertText("---",headerFormat); } for (int cellNumber = 1; cellNumber &lt;= 5; ++cellNumber) { QTextTableCell cell = table-&gt;cellAt(1, cellNumber-1); QTextCharFormat headerCellFormat = cell.format(); QTextCursor cellCursor = cell.lastCursorPosition(); headerCellFormat.setBackground(QColor(0 + (cellNumber * 50), 222, 222, 127)); cell.setFormat(headerCellFormat); cellCursor.clearSelection(); cellCursor.insertText("---",headerFormat); } cursor.endEditBlock(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload