如何在qtextttable中更改行高度
How to change row height in QTextTable
我正在编写复杂的富文本编辑器,源自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);
}
似乎可以使用setHTML(QString)或insertHTML(QString)函数来插入样式表。
当对样式表使用此函数时,样式表只会应用于文档中的当前块。为了应用一个样式在整个文档中使用QTextDocument::setDefaultStyleSheet()相反。
裁判:http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/qtextedit.html insertHtml
除了使用垫片....根据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>
如果你只是想使行高比他们的文本高度需要,你可以尝试插入一个0xN透明图像在行的第一个单元格(或1xN如果Qt不让你做零宽度)。
也可能设置表格单元格的顶部padding with qtextttablecellformat::setTopPadding()或QTextBlockFormat::setTopMargin()设置顶部margin。但是据我所知,内边距和边距都是添加到文本布局高度的,所以它们都不适合设置绝对高度。
你看过Calligra吗?它的libs/kotext和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也可用)
- C++:如何根据地形高度更新玩家身高?
- 如何更改QComboBox项目的高度大小?
- 更改高度贴图,使其在 4x4 网格上显示 16 个 hieghtmap
- 我试图用这段代码找到二叉树的高度,但它一直返回 0,有人可以告诉我为什么吗?
- C++:如何计算二叉树中其值模块高度小于 2 的节点数?
- 如何使用 C++ gdal 库将栅格地理从 EGM96 转换为 WGS84 椭球体高度基准面
- 从具有父指针和左子树和右子树高度的树中删除
- 程序输入名称和高度并显示它。我不知道如何显示列表中最高人的姓名和身高
- 我正在尝试创建一个 C++ 贪吃蛇游戏,但我似乎无法绘制第二个高度边框,我该如何解决这个问题?
- 计算树高度的函数
- 尝试创建一个程序来查找非二叉树的高度.最终得到一个很长的循环,没有答案
- 计算BST返回-1的高度混淆
- 使用递归计算一个函数中的高度和大小
- 如何从2D数组为QHeightMapSurfaceDataProxy创建高度图以显示2D傅立叶变换结果
- 接受来自键盘的树节点以确定其高度
- 在 C++ 中使用平展数组语法,崩溃取决于宽度/高度
- 在一行中初始化指针(新uint8_t[高度*宽度*3])
- 在高度模板化的库中进行代码混淆
- ID3DXFont :文本被拉伸,如何获取字体的宽度和高度?
- 如何在qtextttable中更改行高度