Qt5: Styling the checkbox of a checkable QTreeWidgetItem



  • In my app I have stylesheets for QCheckBox. I created a QTreeViewWidget with QTreeWidgetItems that has been made checkable by setting the flag Qt::ItemIsUserCheckable.

    I was expecting that the checkbox that is displayed will by styled according to the already existing QCheckBox styles. Unfortunately that doesn't happen. This begs the question: how to 'access' that checkbox of the QTreeWidgetItems?

    I tried QTreeView::item as well as QTreeView::indicator and also the combination QTreeView::item::indicator, none of which seem to function. So what is the correct syntax?



  • As it turned out, one must explicitly say QTreeView::indicator:unchecked in order to set the general settings like background color for this checkbox. That was a bit surprising, as this is not needed for instance for QCheckbox::indicator or QGroupBox::indicator, but the solution is now here for posterity



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.