Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent page break in QTextDocument block or frame?

Tags:

c++

qt

Is it possible to prevent page break anywhere inside table in QTextDocument?

In my QTextDocument I have a plenty of larger images created from small image blocks. Adding large images seeems to be a waste of resources, so an obvious solution seems to be creating a table, putting small image in each cell.

The problem is that now these tables can have page breaks after each row. The only way to prevent it I know is to call setPageBreakPolicy() for each table/frame format, but this requires obligatory page break before each larger image. I would like to have these page breaks only if necessary (larger image does not fit).

Is it possible to do what I want?

like image 954
Michal Avatar asked Oct 06 '22 11:10

Michal


1 Answers

For a QTextTable, you can prevent splitting it over multiple pages by setting the headerRowCount property of the QTextTableFormat equal to the number of rows in the table. This property sets the number of rows that are repeated when a page boundary is crossed, repeating the table header. If you set you entire table to be the header, the whole table is always placed on a single page.

One warning: do not do this with tables that potentially do not fit on a single page. Qt will mess things up in this case.

I hope Qt will add some extra flags to the pageBreakPolicy property in the future, so that we can create unbreakable tables/frames in a clean way.

like image 164
Johan van Rooij Avatar answered Oct 12 '22 10:10

Johan van Rooij