本文介绍了设置包含 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.
推荐答案
据我所知,没有简单的方法可以做到.您必须对表格列的宽度求和,然后为标题添加空间.您还必须为垂直滚动条和小部件框架添加空间.这是一种方法,
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,
class myTableWidget(QtGui.QTableWidget):
def sizeHint(self):
width = 0
for i in range(self.columnCount()):
width += self.columnWidth(i)
width += self.verticalHeader().sizeHint().width()
width += self.verticalScrollBar().sizeHint().width()
width += self.frameWidth()*2
return QtCore.QSize(width,self.height())
这篇关于设置包含 TableWidget 的对话窗口的最佳大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!