c++ - 如何更改 QTextTable 中的行高

标签 c++ qt qtextedit

我正在编写复杂的富文本编辑器,它源自 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/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>

关于c++ - 如何更改 QTextTable 中的行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15518211/

相关文章:

c++ - 控制台应用程序中的 Linux Qt QSystemTrayIcon

c++ - 无法将 QPushButton 信号连接到 QGraphicsView 插槽

python - 如何在 PyQt4 中选择性地设置文本的前景色

c++ - 如果在循环内声明了一个指针变量,它是否与循环的每次传递都与相同的内存地址相关联?

c++ - 如何用字体计算多字符串的宽度和高度?

c++ - 为什么不从0开始定义多维数组呢?

c++ - QTextEdit 中的 Qt textChange()

c++ - 使用 for 循环加载数组

c++ - QT 与 wxWidgets

python - PyQt4:如何将印地语文本添加到 QTextEdit