设置包含 TableWidget 的对话框窗口的最佳大小
我编写了一个小对话框,其中仅包含一个 TableWigdet。如何确定表格的水平尺寸?我想调整对话框窗口的大小,以便在没有水平滚动条的情况下显示表格。
I wrote a little dialog which only contains a TableWigdet. How can I determine the horizontal size of the table ? I want to resize the dialog window so that the table is displayed without a horizontal scrollbar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,没有简单的方法可以做到这一点。您必须对表格列的宽度进行求和,然后为标题添加空间。您还必须为垂直滚动条和小部件框架添加空间。这是一种方法,
As far as I know, there's no easy way to do it. You have to sum over the widths of the table's columns and then add space for the headers. You also have to add space for the vertical scrollbar and the widget frame. Here is one way to do it,
您可以使用类似的东西(我希望有足够的注释):
当行标题发生变化时,整个垂直标题的宽度会发生变化,但在信号
headerDataChanged
发出后不会立即发生变化。那就是为什么我在
QTableWidget
实际完成后使用QTimer
调用updateGeometry
(当sizeHint
更改时必须调用)更新了垂直标题宽度。You could use something like that (commented enough I hope):
When a row header changes, the width of the whole vertical header changes, but not right away after the signal
headerDataChanged
is emitted.That's why I used a
QTimer
to call theupdateGeometry
(which must be called whensizeHint
changes) afterQTableWidget
has actually updated the vertical header width.