QTextCursor insertText not working
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.
QTextTableFormat channelBankFormat;
channelBankFormat.setAlignment(Qt::AlignHCenter);
//channelBankFormat.setHeight(8);
channelBankFormat.setColumnWidthConstraints(constraints);
channelBankFormat.setBorder(0);
ChannelBank->clear开发者_StackOverflow社区();
QTextCursor cursor = ChannelBank->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 <= 5; ++cellNumber) {
QTextTableCell cell = table->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 <= 5; ++cellNumber) {
QTextTableCell cell = table->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();
Found the culprit : channelBankFormat.setHeight(8);
精彩评论