Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change row height in QTextTable

Tags:

c++

qt

qtextedit

I'm writing the complicated rich text editor, derived from QTextEdit class. It must be able to insert, resize, and apply various formatting to embedded tables.

I found function for setup column widths (setColumnWidthConstraints). But there is no one to change _rows_ heights.

Is there any way to achieve this?

Example code:

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); } 
like image 908
eraxillan Avatar asked Mar 20 '13 08:03

eraxillan


People also ask

How do you adjust row height in a table?

To set the row height to a specific measurement, click a cell in the row that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Row Height box, and then specify the height you want. To use the ruler, select a cell in the table, and then drag the markers on the ruler.


2 Answers

it seems that you can use the setHTML(QString) or insertHTML(QString) functions to insert a stylesheet.

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.

ref: http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/qtextedit.html#insertHtml

appart from using shims....according to http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/richtext-html-subset.html you can set the font declaration.

Qt seems to have targeted the CSS2.1 specification, which is as followed.. http://www.w3.org/TR/CSS2/fonts.html#propdef-font

have you tried specifying the font within the table row.

pass the following string using insertHTML, where this string is delcared as a QString

<style> table > tr {font-size: normal normal 400 12px/24px serif;} </style> 
like image 89
Brett Caswell Avatar answered Sep 18 '22 13:09

Brett Caswell


If you just want to make rows taller than their text height would require, you could try inserting a 0xN transparent image in the first cell of the row (or 1xN if Qt won't let you do zero-width).

It might also be possible to set the table cell's top padding with QTextTableCellFormat::setTopPadding() or maybe set the top margin with QTextBlockFormat::setTopMargin(). But both padding and margins are added to the text layout height AFAIK, so neither of them is very good for setting an absolute height.

Have you looked at Calligra? Its libs/kotext and libs/textlayout libraries implement a custom QAbstractTextDocumentLayout with much richer table support than QTextEdit.

like image 29
bks Avatar answered Sep 18 '22 13:09

bks