如何消除 QTableWidget 中的空白?
如何摆脱应用程序中的空白:
我想摆脱其中的空白我的 QTableWidget(蓝色箭头)。我该怎么做?
这是我的应用程序的代码:
gridLayout = QGridLayout()
#add other widgets
currentItemsTable = QTableWidget(4, 2)
currentDeviceIconLabel = QLabel("Current Device Icon: ")
self.currentDeviceIcon = QLabel()
currentAppIconLabel = QLabel("Current App Icon: ")
self.currentAppIcon = QLabel()
currentTitleLabel = QLabel("Current Title: ")
self.currentTitle = QLabel(self.getCurrentTitle())
currentSubtitleLabel = QLabel("Current Subtitle: ")
self.currentSubtitle = QLabel(self.getCurrentSubtitle())
currentItemsTable.setCellWidget(0, 0, currentDeviceIconLabel)
currentItemsTable.setCellWidget(0, 1, self.currentDeviceIcon)
currentItemsTable.setCellWidget(1, 0, currentAppIconLabel)
currentItemsTable.setCellWidget(1, 1, self.currentAppIcon)
currentItemsTable.setCellWidget(2, 0, currentTitleLabel)
currentItemsTable.setCellWidget(2, 1, self.currentTitle)
currentItemsTable.setCellWidget(3, 0, currentSubtitleLabel)
currentItemsTable.setCellWidget(3, 1, self.currentSubtitle)
currentItemsTable.horizontalHeader().hide()
currentItemsTable.resizeColumnsToContents()
currentItemsTable.resizeRowsToContents()
currentItemsTable.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
gridLayout.addWidget(currentItemsTable, 1, 4, 8, 2)
另外,如何让 QTableWidget 根据行和列内容调整大小?我不想要任何滚动条。
How do I get rid of the whitespace in my application:
I would like to get rid of the whitespace in my QTableWidget (blue arrow). How do I do it?
Here is the code for my application:
gridLayout = QGridLayout()
#add other widgets
currentItemsTable = QTableWidget(4, 2)
currentDeviceIconLabel = QLabel("Current Device Icon: ")
self.currentDeviceIcon = QLabel()
currentAppIconLabel = QLabel("Current App Icon: ")
self.currentAppIcon = QLabel()
currentTitleLabel = QLabel("Current Title: ")
self.currentTitle = QLabel(self.getCurrentTitle())
currentSubtitleLabel = QLabel("Current Subtitle: ")
self.currentSubtitle = QLabel(self.getCurrentSubtitle())
currentItemsTable.setCellWidget(0, 0, currentDeviceIconLabel)
currentItemsTable.setCellWidget(0, 1, self.currentDeviceIcon)
currentItemsTable.setCellWidget(1, 0, currentAppIconLabel)
currentItemsTable.setCellWidget(1, 1, self.currentAppIcon)
currentItemsTable.setCellWidget(2, 0, currentTitleLabel)
currentItemsTable.setCellWidget(2, 1, self.currentTitle)
currentItemsTable.setCellWidget(3, 0, currentSubtitleLabel)
currentItemsTable.setCellWidget(3, 1, self.currentSubtitle)
currentItemsTable.horizontalHeader().hide()
currentItemsTable.resizeColumnsToContents()
currentItemsTable.resizeRowsToContents()
currentItemsTable.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
gridLayout.addWidget(currentItemsTable, 1, 4, 8, 2)
Additionally, how do I get the QTableWidget to resize with the row and column contents? I don't want any scroll bars.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该使用这个:
你应该在调整大小后调用它....toContents(),并且任何时候你要调整内容的大小,你应该首先设置StretchLastSection(False),比如:
或者你会在调整大小时得到奇怪的效果。
I think you should be using this:
You should call this after resize....toContents() and any time you are going to resize for contents you should first setStretchLastSection(False), something like:
Or you will get strange effects on resize.