我正在编写从QTextEdit类派生的复杂的富文本编辑器.它必须能够插入,调整大小并将各种格式应用于嵌入式表.
我找到了设置列宽度的函数(setColumnWidthConstraints).但没有人可以change _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);
}
Run Code Online (Sandbox Code Playgroud)
似乎您可以使用 setHTML(QString) 或 insertHTML(QString) 函数来插入样式表。
当将此函数与样式表一起使用时,样式表将仅应用于文档中的当前块。为了在整个文档中应用样式表,请使用 QTextDocument::setDefaultStyleSheet()。
除了使用垫片....根据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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3231 次 |
| 最近记录: |