2013-03-20 62 views
31

我正在編寫複雜的富文本編輯器,派生自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); 
} 
+0

你可以使用QTextFrameFormat ::自動調用setHeight( qreal高度) – 2013-03-20 10:32:32

+1

@Cool_Coder這只是改變了框架的高度(即將顯示邊框的位置)。但我需要指定表格的任何單獨行的高度。 – eraxillan 2013-03-20 11:24:18

+0

可以請顯示一些代碼,以便我可以對此發表評論? – 2013-03-20 11:31:47

回答

1

似乎可以使用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> 
0

如果你只想讓行比他們的文字高度較高需要下列字符串,你可以嘗試插入0xN透明圖像在行的第一個單元格(或1xN,如果Qt不會讓你做零寬度)。

也許可以使用QTextTableCellFormat :: setTopPadding()來設置表格單元格的頂部填充,也可以使用QTextBlockFormat :: setTopMargin()設置頂部邊距。但是,填充和邊距都會添加到文本佈局高度AFAIK中,所以它們都不太適合設置絕對高度。您是否看過Calligra?它的libs/kotext and libs/textlayout庫實現了一個定製的QAbstractTextDocumentLayout,它比QTextEdit具有更豐富的表支持。