我正在尝试使用QTextTable在QT中创建一个表。当我设置背景和文本时,第一行运行得很好,但是第二行只应用了格式化,但是insertText函数似乎不适合我。我也尝试过insertHTML,但在row2上似乎什么都不管用。
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();发布于 2011-04-14 00:49:21
找到罪魁祸首: channelBankFormat.setHeight(8);
https://stackoverflow.com/questions/5624300
复制相似问题