With a simple QPushButton, if I want to use custom images while the size of the button is determined by a layout (so it can be scaled freely), the only possibility is to override border-image
in the style sheet. If I add the image as an image
attribute instead of border-image
, then the images are not scaled down.
However, if I use a QRadioButton and override the image
or border-image
, the circle of the radio button remains visible. I found no way of hiding it or overriding it.
A possibility would be to ignore the label, and change the circle icon itself. This can be done by overriding QRadioButton:indicator
, however, it doesn't accept border-image
, it only accepts image
which will not scale.
Is there any way to solve this, or am I stuck with using QPushButton with setCheckable(true)
, and handle the other buttons manually whenever one of them is pressed?
I tried specifying a border-image for the label, and a non-existing image for the indicator:
ui->radioButton->setStyleSheet(
"QRadioButton { border-image: url(:/img/off.png) 0 0 0 0 stretch stretch; }"
"QRadioButton:checked { border-image: url(:/img/on.png) 0 0 0 0 stretch stretch; }"
"QRadioButton:pressed { border-image: url(:/img/off_pressed.png) 0 0 0 0 stretch stretch; }"
"QRadioButton:checked:pressed { border-image: url(:/img/on_pressed.png) 0 0 0 0 stretch stretch; }"
"QRadioButton:indicator:unchecked {image: url()}"
"QRadioButton:indicator:checked {image: url()}"
"QRadioButton:indicator:unchecked:pressed {image: url()}"
"QRadioButton:indicator:checked:pressed {image: url()}"
);
The problem is, that although the circle is now not visible, it still takes up space, so the image doesn't fill up the entire available space.