简体   繁体   English

我如何在我的QTableWidget中摆脱这个空白?

[英]How do I get rid of this whitespace in my 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). 我想摆脱QTableWidget中的空格(蓝色箭头)。 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? 另外,如何获取QTableWidget来调整行和列内容的大小? I don't want any scroll bars. 我不要任何滚动条。

I think you should be using this: 我认为您应该使用此:

currentItemsTable.horizontalHeader().setStretchLastSection(True)
currentItemsTable.verticalHeader().setStretchLastSection(True)

You should call this after resize....toContents() and any time you are going to resize for contents you should first setStretchLastSection(False), something like: 您应该在调整大小.... toContents()之后调用此方法,并且每次要调整内容的大小时,都应该首先设置setStretchLastSection(False),例如:

currentItemsTable.verticalHeader().setStretchLastSection(False)
currentItemsTable.resizeRowsToContents()
currentItemsTable.verticalHeader().setStretchLastSection(True)

Or you will get strange effects on resize. 否则您会在调整大小时得到奇怪的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM