Why are you asking this on a Qt forum? This seems like HTML related issue.
Why are you asking this on a Qt forum? This seems like HTML related issue.
I am writing a reporting tool with Qt and data are in table. I make table with HTML but I can not get cell width
I found a javascript code for my problem:Can I use this?Qt Code:
document.getElementById('tbl_id').rows[0].cells[0].offsetWidthTo copy to clipboard, switch view to plain text mode
Last edited by sipahi; 1st February 2013 at 01:24.
You can use whatever you wish, just remember the table has no physical attributes until the page is rendered somewhere.
Can you explain me how can I use this javascript code. I always get 0 as .
if you design a report you dont need to invoke the html table its just a container populated with what you want for printing or exporting it to pdf or any formate
I changed my code because it seems impossible for me.
Now I created table using QTextTable.
Qt Code:
QTextTableCellFormat cellFormat; cellFormat.setLeftPadding(7); cellFormat.setRightPadding(7); QTextTableFormat tableFormat; tableFormat.setAlignment(Qt::AlignLeft); tableFormat.setBorderBrush(blackBrush); tableFormat.setBorder(.5); tableFormat.setCellSpacing(0); tableFormat.setAlignment(Qt::AlignLeft);To copy to clipboard, switch view to plain text mode
I noticed setColumnWidthConstraints function for column width. But cell width changes according to text.
Is there a way to get cell width in QTextTable?
You can't get cell width of any table before the rendering mechanism knows what font is used, what is the content of all other cells in the table and so on. It doesn't matter whether you are using HTML or QTextDocument, the "problem" is the same. You need to trigger the layouting functionality of the engine you are using.
thank you for your patient and assistance @wysota.
I am new in Qt and I do not know completely what Qt can do.
Basically I am trying to create two separate tables which have exactly same size and number of columns.
And then print out two tables. But contents of tables are different. Because of that widths of columns become different.
And also I don not know how can I trigger the layouting functionality.
Last edited by sipahi; 2nd February 2013 at 10:44.
In your first post you created a table in html with a width of 100%.
You can do the same for every cell in a row. Set them all to a fixed pixel value or percentage, except for one column. That one will fill up the remaining space in a row.
Also, you don't have to do it for every row, as all cells in a column will, normally, have the same width.
All this can be done with an element like <td width=100> or using css stylesheets. You know how to use stylesheets as you used it in the original table definition, class="tbl".
The main difference in this approach is that you now set a width instead of trying to get it from a renderer that is not yet in action (as others told you before).
It's not about Qt. HTML holds information about the logical structure of a document and not its physical attributes. Only when the document is displayed in some kind of browser, it gains those physical attributes but only for particular input parameters like the browser's default font, window size, device resolution, CSS definitions and so on.
Basically I am trying to create two separate tables which have exactly same size and number of columns.
And then print out two tables. But contents of tables are different. Because of that widths of columns become different.
It depends on the document engine you are using. For HTML you can use WebKit, for QTextDocument you can use QAbstractTextDocumentLayout and QTextDocument itself. You can iterate over all rows in the two tables you have, find a maximum width cells in your particular column occupy and then set that width on those columns explicitly (if the engine allows it).And also I don not know how can I trigger the layouting functionality.
Bookmarks