PDA

View Full Version : QTable Column width supporting fonts



kommu
25th December 2007, 16:45
I am working on the QTable which have the columns with specific sizes. So according to QFont and resolution of the system, I should display the column correctly fitting max characters per the column.

There will be no scroll bar for the qtable because, I am working for QT/Embedded system which will not have mouse. Only touch screen is available.

wysota
25th December 2007, 17:43
And what is the question?

kommu
26th December 2007, 11:10
I should display the column correctly fitting max characters per the column. How?

wysota
26th December 2007, 11:18
I don't understand the question. Could you explain what you mean and what did you already try? What is the exact problem you are facing? Note, that this is not an outsourcing company website - we help you solve your problems, not solve your problems for you.

kommu
26th December 2007, 11:33
I want to display data in a spreadsheet like format on the screen.
I used QTable to set columns and column widths.
I have 5 columns.
column1 has 7 as column width
column2 has 30 as column width
column3 has 36 as column width
column4 has 30 as column width
column5 has 30 as column width.

But, with the specified font and font family, size, I should display the column width with label. There will be no scrollbar, no mouse.

I had taken QFontMetrics fm(QApplication::fontmetrics());
fontWidth=fm.width("W");//widest character width in pixels
so for column1 = 7 * fm.width("W");
But, it is going beyond screen limits for all the columns to display.

please solve my problem. If you are not clear with this, please revert back.

wysota
26th December 2007, 12:06
Hmm.. as far as I know "m" is the widest character. Remember that cells have margins, so if you want to display 7 characters, you need fm.width("m")*7 + 2*margin. But before you do that, take a look at QHeader::setStretchEnabled - if you enable stretch for all columns, they will scale when you resize the table.

kommu
27th December 2007, 06:06
I think W is the widest character. Since,
fm.width("W") = 15 with font family set
fm.width("M") = 13. with font family set

Tried in the same way for M also. But it is not coming in the screen limits.
As mentioned in previous mails, the characters are fitting into the columns, but QTable is not coming in the screen limits.

If we use setColumnStrechable(true). All columns are resized equally and coming in the screen limits, but max characters of a column is not proper.

The issue is with max characters per a column and QTable to come in screen limits.

wysota
27th December 2007, 11:18
If the table is not wide enough then resize it according to the header width. See QTable::horizontalHeader().