删除QTableWidget单元格中的空间

时间:2019-09-02 06:36:14

标签: python python-3.x pyqt pyqt5 qtablewidget

我想将log.retention.check.interval.msQLineEdit放在QLable中的同一单元格中。此单元小部件已创建了我在互联网上修改的以下代码。

QTableWidget

通过单击鼠标左键,该单元格将在class HiddenLabel(QLabel): ''' QLable hide when mouse pressed ''' def __init__(self, buddy, taskline, parent = None): super(HiddenLabel, self).__init__(parent) self.setFixedHeight(30) self.buddy = buddy self.taskline = taskline # When it's clicked, hide itself and show its buddy def mousePressEvent(self, event): # left click to edit if event.button() == QtCore.Qt.LeftButton: self.hide() self.buddy.setText(self.taskline.plain_text) self.buddy.show() self.buddy.setFocus() # Set focus on buddy so user doesn't have to click again class EditableCell(QWidget): ''' QLineEdit show when HiddenLabel is hidden ''' def __init__(self, taskline, parent = None): super(EditableCell, self).__init__(parent) self.taskline = taskline # Create ui self.myEdit = QLineEdit() self.myEdit.setFixedHeight(30) self.myEdit.hide() # Hide line edit self.myEdit.editingFinished.connect(self.textEdited) # Create our custom label, and assign myEdit as its buddy self.myLabel = HiddenLabel(self.myEdit, self.taskline) self.myLabel.setText(self.taskline.enrich_text()) # Change vertical size policy so they both match and you don't get popping when switching #self.myLabel.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed) # Put them under a layout together hLayout = QHBoxLayout() hLayout.addWidget(self.myLabel) hLayout.addWidget(self.myEdit) self.setLayout(hLayout) def textEdited(self): # If the input is left empty, revert back to the label showing print('edit finished') print(self.myEdit.text()) taskline = TaskLine() taskline.parser(self.myEdit.text()) self.taskline = taskline self.myLabel.setText(taskline.enrich_text()) self.myEdit.hide() self.myLabel.show() QLineEdit之间切换。 enter image description here
如屏幕截图所示,我要删除单元格边框和单元小部件之间的空白。

我认为可以通过样式设置进行调整,但是我没有找到任何有关Qt样式设置的有用文档。我希望有人可以使用

1 个答案:

答案 0 :(得分:0)

您必须将布局边距设置为0:

hLayout.setContentsMargins(0, 0, 0, 0)

由于the docs指出它们取决于样式和平台:

  

void QLayout :: setContentsMargins(int左,int顶部,int右,int   底部)

     

设置左,上,右和下边距以在周围使用   布局。

     

默认情况下,QLayout使用样式提供的值。在大多数   平台,所有方向的边距均为11像素。