Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting style on QTreeWidget root items (PyQT)



  • Is there a way to set a style for only the root items in a QTreeWidget?

    For example if below is my tree, I'd like to set a style on just the "/bob" and "/tom" items.

    /bob
         /photos
         /documents
    /tom
        /photos
        /documents
    

    I tried this and a few other variations with no luck:

    TREE_STYLESHEET = """
        QTreeView::item:first  {
            background-color: red;
        }
    """
    self.MyTreeWidget.setStyleSheet(TREE_STYLESHEET)
    

    I've been looking here:

    http://doc.qt.io/qt-5/stylesheet-reference.html


Log in to reply