Qt4 QTextCursor insertText不工作

Qt4 QTextCursor insertText不工作,qt4,Qt4,我正在尝试使用QTextTable在QT中创建一个表。当我设置背景和文本时,第一行工作正常,但第二行仅应用格式化,但insertText函数似乎不适合我。我也尝试过insertHTML,但在第2排似乎没有任何效果 QTextTableFormat channelBankFormat; channelBankFormat.setAlignment(Qt::AlignHCenter); //channelBankFormat.setHeight(8); channelBankFormat.setCo

我正在尝试使用QTextTable在QT中创建一个表。当我设置背景和文本时,第一行工作正常,但第二行仅应用格式化,但insertText函数似乎不适合我。我也尝试过insertHTML,但在第2排似乎没有任何效果

QTextTableFormat channelBankFormat;
channelBankFormat.setAlignment(Qt::AlignHCenter);
//channelBankFormat.setHeight(8);
channelBankFormat.setColumnWidthConstraints(constraints);
channelBankFormat.setBorder(0);

ChannelBank->clear();
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();
QTextTableFormat channelBankFormat;
channelBankFormat.setAlignment(Qt::AlignHCenter);
//设置高度(8);
channelBankFormat.setColumnWidthConstraints(约束);
channelBankFormat.setBorder(0);
ChannelBank->clear();
QTextCursor cursor=ChannelBank->textCursor();
cursor.beginEditBlock();
QTextTable*table=cursor.insertTable(2,5,channelBankFormat);
QTextCharFormat headerFormat=cursor.charFormat();
头部性能设置字体重量(字体::粗体);
头部执行器。设置FontPointSize(8);
QTextCharFormat dataFormat=cursor.charFormat();
dataFormat.setFontPointSize(12);
QTextBlockFormat中心对齐;
setAlignment(Qt::AlignCenter);
for(int cellNumber=1;cellNumber cellAt(0,cellNumber-1);
QTextCharFormat headerCellFormat=cell.format();
QTextCursor cellCursor=cell.firstCursorPosition();
headerCellFormat.setBackground(QColor(0+(cellNumber*50),222222127));
cell.setFormat(headerCellFormat);
cellCursor.clearSelection();
cellCursor.insertText(“--”,headerFormat);
}
for(int cellNumber=1;cellNumber cellAt(1,cellNumber-1);
QTextCharFormat headerCellFormat=cell.format();
QTextCursor cellCursor=cell.lastCursorPosition();
headerCellFormat.setBackground(QColor(0+(cellNumber*50),222222127));
cell.setFormat(headerCellFormat);
cellCursor.clearSelection();
cellCursor.insertText(“--”,headerFormat);
}
cursor.endEditBlock();
找到了罪犯: 设置高度(8)