I want to create a squared radio button, with the text inside the button. Is that possible? I think the button shape could be changed trough css, but what about the text?
Any hint?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Rather than trying to deform a QRadioButton into something which visually resembles a QPushButton, I would simply use a QPushButton with some custom logic.
You won’t have to worry about the visual aspect then, while the logic itself is not all that hard to write.
As stated by @besworland, QPushButton inherits from QAbstractButton, which already has the option to be checkable or not. You can set this via
setCheckable(bool).To mimic the “exclusive” behaviour of a set of QRadioButtons, you can add your buttons to a QButtonGroup and make it an exclusive one. As stated in the documentation “An exclusive button group switches off all checkable (toggle) buttons except the one that was clicked.” You can use a QButtonGroup’s
setExclusive(bool)method for that.In any case, I would consider those easier options than transforming a QRadioButton to fit your needs.