Reputation: 1620
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);
}
Upvotes: 32
Views: 4668
Reputation: 2083
Reimplementing QAbstractTextDocumentLayout
.
Relayouting the Document Layout.
You can change the row height of QTextTable
.
https://www.youtube.com/watch?v=1VunwWqO-kE&t=14s
Upvotes: 0
Reputation: 773
Insert a stylesheet using this->document()->setDefaultStyleSheet("css goes here");
See http://qt-project.org/doc/qt-5.0/qtwidgets/qtextedit.html#document-prop and http://qt-project.org/doc/qt-5.0/qtgui/qtextdocument.html#defaultStyleSheet-prop
(links go to Qt5 docs, but these functions are available in Qt4 also.)
Upvotes: 0
Reputation: 1360
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.
Upvotes: 1
Reputation: 1504
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.
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>
Upvotes: 1