我正在编写一个复杂的富文本编辑器,继承自QTextEdit
类。它必须能够插入、调整大小并应用各种格式到嵌入表格中。
我发现了设置列宽度的函数 (setColumnWidthConstraints)。 但是没有函数可以改变行高度。
是否有任何方法可以实现这个功能?
示例代码:
void CustomTextEdit::insertTable (int rows_cnt, int columns_cnt)
{
QTextCursor cursor = textCursor ();
QTextTableFormat table_format;
table_format.setCellPadding (5);
// TODO: This call just changed the frame border height, not table itself.
//table_format.setHeight (50);
// Setup columns widths - all is working perfectly.
QVector <QTextLength> col_widths;
for (int i = 0; i < columns_cnt; ++i)
col_widths << QTextLength (QTextLength::PercentageLength, 100.0 / columns_cnt);
table_format.setColumnWidthConstraints (col_widths);
// ...But there is no similar function as setRowHeighConstraints for rows!
// Insert our table with specified format settings
cursor.insertTable (rows_cnt, columns_cnt, table_format);
}
setCellPadding
强制设置为一个较大的数字来达到所需的高度,然后再使用setColumnWidthConstraints
将宽度调整回来。 - Nicholas Smith