Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide circle from radio button and only show icon in qt?

Tags:

css

qt

I want user to select a theme which he wants to apply to the document. So i have created a popup dialog which has multiple themes which are qradiobutton. But I want to display only icons and remove circle from the widget.

I have tried visible:hidden for the radio button but that didn't worked.

like image 948
VIVEK SHARMA Avatar asked Oct 14 '25 18:10

VIVEK SHARMA


1 Answers

If you want to customize QRadioButton with style-sheets I suggest you check the reference documentation: https://doc.qt.io/qt-5/stylesheet-reference.html#qradiobutton-widget

You should also find useful the examples given in Qt documentation as it shows how to replace the check indicator by different images:

QRadioButton::indicator {
    width: 13px;
    height: 13px;
}

QRadioButton::indicator::unchecked {
    image: url(:/images/radiobutton_unchecked.png);
}

QRadioButton::indicator:unchecked:hover {
    image: url(:/images/radiobutton_unchecked_hover.png);
}

https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qradiobutton

If you do this yo can just use the indicator to display the icon and leave the QRadioButton label empty.

However, I have to warn you, depending on which QStyle you are using, it could happen that using style-sheets destroys completely the style of a component. A general example is: you are using a style where buttons have round corners, you use style-sheets to change the font of the button and as a result the button does not have round corners anymore. This is caused by incompatibilities between some QStyle and the style-sheet mechanism. If you do not want to make a multi platform app, it might not be an issue as you will use only one style, but if you make an multi platform app, you have to check every possible style you platform can have on the different platforms.

So if you want to have a QRadioButton without indicator and not use style-sheets, you can do it in C++ directly by subclassing QAbstractButton. Just make sure you set your class to be autoExclusive so that is will behave like a radio button.

like image 104
Benjamin T Avatar answered Oct 17 '25 10:10

Benjamin T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!