QTable - 如何调整表视图的大小?
我将表视图拖放到表单应用程序上。我想知道如何根据我添加的行数以编程方式调整表基的大小。如果您能向 mw 展示一些代码,我们将不胜感激。 谢谢
I drag and drop a Table 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您可以使用 setFixedHeight 方法,棘手的部分是如何计算正确的高度。
除了行数之外,还有一些因素会极大地影响所需的高度。
a) 是否显示horizontalHeader
b) 行的高度是否一致。
我们假设它是可见的,并且行的高度是统一的。那么我们想要的高度就是 - 标题的高度 + 通常行* 行数,再加上几张用于边框间距的图片。
现在,如果标题不可见——我们可以通过调用horizontalHeader()->isVisible来检查,那么显然我们可以忽略它的高度。
如果我们的行的高度不统一,那么我们不能仅仅计算它,我们必须循环遍历所有行并单独获取每个行的高度。
然后,正如我之前所说,调用 setFixedHeight,就可以了。除非有任何奇怪的样式或类似的东西,这应该涵盖所有内容。
祝你好运。
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.
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.