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

Center align the icon in QAbstractItemView using stylesheets



  • I have a custom model for a table view. My data function returns a QImage for the decoration role. But this image is not center aligned (horizontally and vertically). I tried using the following style sheet. But the image is still not centered. Please help.

    QAbstractItemView::icon {
    border: 1px solid black;
    }

    QAbstractItemView {
    subcontrol-position: center center;
    }



  • Try to use QAbstractItemView::item



  • I tried using it in the following ways but these did not work as well.

    QAbstractItemView::item {
    subcontrol-position: center center;
    }

    And

    QAbstractItemView::item::icon {
    subcontrol-position: center center;
    }


Log in to reply