Search code examples
pythonqtcheckboxqt-designerqtstylesheets

Qt Designer custom checkbox relative path


I am trying to make a Checkbox in Qt Designer that uses custom png images instead of the checkbox.

I do this by using a custom stylesheet with following content:

QCheckBox::indicator {
 width: 30px;
 height: 30px;
 }

QCheckBox::indicator:checked
{
 image: url(radio_selected.png);
}
QCheckBox::indicator:unchecked
{
  image: url(C:\\MYPROJECT\\subdirectory\\radio_unselected.png);
}

QCheckBox::indicator:checked:hover
{
  image: url(C:\\MYPROJECT\\subdirectory\\radio_selected.png);
}
QCheckBox::indicator:unchecked:hover
{
  image: url(C:\\MYPROJECT\\subdirectory\\radio_unselected.png);
}

The absolute paths using dual backslashes deliver the desired result. The relative path entry doesn't work. Neither does

QCheckBox::indicator:checked
{
 image: url(./radio_selected.png);
}

nor

QCheckBox::indicator:checked
{
 image: url(.\radio_selected.png);
}

nor

QCheckBox::indicator:checked
{
 image: url("radio_selected.png");
}

nor

QCheckBox::indicator:checked
{
 image: url(file:///radio_selected.png);
}

or anything else that i've tried... what am I missing here?


Solution

  • For future reference, when using the Qt designer with custom QSS, if you want your image labels to be in a relative path to the *.ui file, one has to use the syntax ./radio_selected.png to make it work.

    It won't show in the editor, but it will work when calling the *.ui file from a script.