Search code examples
pythonpyqtpyside

PyQt remove highlight selection area from QTreeWidget


I have a QTreeWidget and I want to remove the blue highlight area from around the Widget itself, not from the selected item (See image).

enter image description here Any ideas?


Solution

  • I have since found a couple of ways to achieve this, depending on your setup and the desired affect.

    Set the size Policy on the tree widget

    tree_widget.setFocusPolicy(QtCore.Qt.NoFocus)
    

    This will stop the QTreeWidget taking focus, preventing the blue outline from appearing.

    Set the style sheet on the tree widget

    tree_widget.setStyleSheet("QTreeView {border: none; outline: 0;}"
    

    This will completely remove the border (which turns blue).

    Bonus, remove the blue border from tree widget items

    tree_widget.setStyleSheet("QTreeView::item {border: none; outline: 0;}")