0

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)

qt misaligned checkbox

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

Korcan Karaokçu
  • 467
  • 4
  • 18
  • 2
    That seems the space left to show the *decorations* of tree item, used to show and toggle the collapsed/expanded state of items and also the "lines" grouping items on the same level. That space is quite important, visually speaking. – musicamante Jul 20 '22 at 03:03
  • There must be a configuration for this. Have you checked all the properties? E.g. I do not see you trying `setSpacing(0);` on your layout, just in case. – László Papp Jul 20 '22 at 07:25
  • @KorcanKaraokçu Try with `self.treeWidget_AddressTable.setRootIsDecorated(False)` – musicamante Jul 20 '22 at 08:57
  • `setRootIsDecorated` works properly, thanks for the answers. @musicamante was right, it's impossible to expand items without it. Laszlo, I've already tried spacing as I stated in the last paragraph, it doesn't work. It just wasn't represented in the last draft of the code – Korcan Karaokçu Jul 20 '22 at 09:59

1 Answers1

0

As stated in the comments, setRootIsDecorated(False) works but it also makes it impossible to expand items for the user. I've found out that the true answer to this was to use setIndentation() with the desired parameter. I'll be accepting this answer, thanks for the help

Korcan Karaokçu
  • 467
  • 4
  • 18