如何更改QTextTable中的行高度
我正在编写复杂的富文本编辑器,派生自QTextEdit
类。它必须能够插入,调整大小,并将各种格式应用于嵌入表格。如何更改QTextTable中的行高度
我找到了设置列宽的函数(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);
}
似乎可以使用setHTML(QString的)或insertHTML(QString的)函数来插入一个样式表。
将此功能与样式表一起使用时,样式表将只有 适用于文档中的当前块。为了在整个文档中应用样式 表,请改为使用QTextDocument :: setDefaultStyleSheet() 。
REF:使用垫片....根据http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/richtext-html-subset.html你可以设置字体声明http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/qtextedit.html#insertHtml
APPART。
的Qt似乎有针对性的CSS2.1规范,这是遵循.. http://www.w3.org/TR/CSS2/fonts.html#propdef-font
你试过表行中指定的字体。
通过使用insertHTML,在此字符串delcared与QString
<style>
table > tr {font-size: normal normal 400 12px/24px serif;}
</style>
如果你只想让行比他们的文字高度较高需要下列字符串,你可以尝试插入0xN透明图像在行的第一个单元格(或1xN,如果Qt不会让你做零宽度)。
也许可以使用QTextTableCellFormat :: setTopPadding()来设置表格单元格的顶部填充,也可以使用QTextBlockFormat :: setTopMargin()设置顶部边距。但是,填充和边距都会添加到文本布局高度AFAIK中,所以它们都不太适合设置绝对高度。您是否看过Calligra?它的libs/kotext and libs/textlayout库实现了一个定制的QAbstractTextDocumentLayout,它比QTextEdit具有更丰富的表支持。
插入使用this->document()->setDefaultStyleSheet("css goes here");
见http://qt-project.org/doc/qt-5.0/qtwidgets/qtextedit.html#document-prop 和http://qt-project.org/doc/qt-5.0/qtgui/qtextdocument.html#defaultStyleSheet-prop样式表
(链接去QT5文档,但这些功能的Qt4可也。)
你可以使用QTextFrameFormat ::自动调用setHeight( qreal高度) – 2013-03-20 10:32:32
@Cool_Coder这只是改变了框架的高度(即将显示边框的位置)。但我需要指定表格的任何单独行的高度。 – eraxillan 2013-03-20 11:24:18
可以请显示一些代码,以便我可以对此发表评论? – 2013-03-20 11:31:47