mardi 18 septembre 2018

Custom checkbox in QTreeView doesnt show

I have a QTreeView which consists of 4 header fields, two of them containing checkboxes (index 1 and 2).

The checkbox in field 1 is enabled and the user is able to check it in order to mark it as favourite, the second checkbox in field 2 is used to display a certain state and is therefore disabled.

The favourite checkbox states are to be displayed with an outline of a star and a filled star icon, which are already included in the images.qrc file (which contains a lot of icons, all working)

In order to only style the favourite checkbox with the star icon i used

ui.myTreeView->setStyleSheet(
"QTreeView::indicator:checked:enabled {
    image: url(:/img/favChecked);
}
QTreeView::indicator:unchecked:enabled {
    image: url(:/img/favUnchecked);
}"

Using the :enabled pseudo state to only target the favourite checkbox as the other one is to remain default style.

So far the second checkbox is displayed as it should, the custom one just doesnt show the desired picture, it is just empty. The invisible checkbox works as intended just doesnt display. I tried numerous approaches:

  • omitting the :enabled pseudo state -> both checkboxes get displayed correctly as stars, its just not what is wanted but it proves the icons work
  • setting it only for one of the checked or unchecked state -> shows the unconfigured state correct and nothing for the other
  • giving the checkbox a certain objectName and using QTreeView#objectName::indicator:checked as selector -> no effect
  • tried this solution, styled QTreeView[cssClass="favourite"]::indicator as well as QCheckBox[cssClass="favourite"]::indicator -> no effect, i guess it is not treated as a "real" QCheckBox and does not access the property when it is a checkable QStandardItem

Is this a known issue and does anybody know a fix/workaround for it? Do you have any other approaches in order to make a better selector?

thanks in advance




Aucun commentaire:

Enregistrer un commentaire