John Thomas
John Thomas

Reputation: 4135

Qt - QTreeView: How to show a checkbox in a themed application?

I inherited a themed application which use Qt as GUI library. Among other things it has a tree of keywords which is built using QTreeView which behaves WRT to the selected items from the folder pane in the standard way:

Ie. if all the items from selection have the keyword 'Plants' assigned then the checkbox of 'Plants' is checked. If none of the items have the said keyword the checkbox is unchecked and if some of the items from selection have assigned the keyword 'Plants' assigned then the checkbox is grayed.

The problem is that while the above model works ok, when the checkbox is grayed (in 'indeterminate' state), this simply disappears from the screen:

Invisible checkbox

The checkbox is still there (the user can click it and works as expected) but it is invisible.

How can I fix this?

...and because I suspect that it is a problem with the theme, I paste here the relevant (IMHO) part from the theme:

QTreeView::indicator{
    border: 0px solid red;
    width: 14px;
    height: 16px;
}

QTreeView::indicator:unchecked{
     image: url(UI:checkbox_unchecked.png);
 }

QTreeView::indicator:unchecked:disabled{
     image: url(UI:checkbox_unchecked_disabled.png);
 }

QTreeView::indicator:checked{
     image: url(UI:checkbox_checked.png);
 }

QTreeView::indicator:checked:disabled{
     image: url(UI:checkbox_checked_disabled.png);
}

QTreeView#UIGroup_TreeView{
    background-color: rgb(40, 40, 40);
    alternate-background-color:  rgb(50, 50, 50);
    border: 0px solid black;
}

Any help?

Upvotes: 2

Views: 1912

Answers (1)

trompa
trompa

Reputation: 2007

As you can see in docs

A QCheckBox has an indeterminate state that your style is not defining an image for.

You should create images for these:

QTreeView::indicator:indeterminate{
     image: url(...);
 }

QTreeView::indicator:indeterminate:disabled{
     image: url(...);
}

Upvotes: 2

Related Questions