I've subclassed QWidget and used setItemWidget to set it as a cell widget. Here's the code for the subclass
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QCheckBox, QLabel
from PyQt5.QtCore import Qt
class QFrozenWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
checkbox = QCheckBox()
label = QLabel()
label.setText("▲")
layout = QHBoxLayout(self)
layout.setAlignment(Qt.AlignLeft)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(checkbox)
layout.addWidget(label)
This is how I set the widget to the cell, treeWidget_AddressTable was already declared in the ui file, it's normal QTreeWidget
current_row = QTreeWidgetItem()
frozen_widget = QFrozenWidget()
self.treeWidget_AddressTable.addTopLevelItem(current_row)
self.treeWidget_AddressTable.setItemWidget(current_row,FROZEN_COL,frozen_widget)
Even with Qt.AlignLeft
or spacing
the checkbox has a gap between itself and the leftmost side of the freeze column. How do I remove it? I've subclassed QWidget as an attempt, I'm open to any kind of neat solution to this
Have a nice day people