我正在编写复杂的富文本编辑器,它源自 QTextEdit
类。它必须能够插入、调整大小并将各种格式应用于嵌入的表格。
我找到了设置列宽的函数 (setColumnWidthConstraints)。
但是没有人改变_rows_ heights
。
有什么办法可以做到吗?
示例代码:
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);
}
最佳答案
看来您可以使用 setHTML(QString) 或 insertHTML(QString) 函数来插入样式表。
When using this function with a style sheet, the style sheet will only apply to the current block in the document. In order to apply a style sheet throughout a document, use QTextDocument::setDefaultStyleSheet() instead.
不使用垫片....根据 http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/richtext-html-subset.html你可以设置字体声明。
Qt 似乎针对的是 CSS2.1 规范,如下所示。http://www.w3.org/TR/CSS2/fonts.html#propdef-font
您是否尝试过在表格行中指定字体。
使用 insertHTML 传递以下字符串,其中该字符串被定义为 QString
<style>
table > tr {font-size: normal normal 400 12px/24px serif;}
</style>
关于c++ - 如何更改 QTextTable 中的行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15518211/