2011-04-11 62 views
0

我想在QT中使用QTextTable製作表格。第一行工作正常,當我設置背景和文本,但第二行只適用於格式化,但insertText函數似乎不適用於我。我也嘗試過insertHTML,但是在row2上沒有任何東西可以用於我。QTextCursor insertText not working

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(); 

回答

0

實測值的罪魁禍首: channelBankFormat.setHeight(8);