QTable - how to resize a table view?
I drag and drop a Tabl开发者_开发百科e view on my form application. I would like to know how can I programatically resize the table base based on the numbers of rows that i add. Appreciate if you can show mw some code. thx
You can use the setFixedHeight method, the tricky part is how to calculate the correct height.
There are a couple of things that will greatly affect the desired height - other than the number of rows.
a) Whether or not the horizontalHeader is shown b) Whether the rows are uniform heights.
Let's assume it is visible, and that the rows are uniform heights. So then our desired height would be - the height of the header + a typically row* the number or rows, plus a couple of pictures for border spacing.
MyTableView->horizontalHeader()->height() + _NumberOfRows * MyTableView->rowHeight(0) + 2
Now, if the header is not visible - which we can check by calling horizontalHeader()->isVisible, then obviously we can leave off it's height.
If our rows are not uniform height, then we can't just calculate it, we'll have to loop through them all and get each of their heights individually.
Then, as I said before, call setFixedHeight, and you're good to go. Barring any weird styling or things like that, this should cover everything.
Good luck.
精彩评论