QRadioButton checks / cancels release in Qt

I find questions related to the verification / removal of QRadioButton. Images that I used to check (white dot) and uncheck (no white dot) are not updated. My problem is this: I implemented several QRadioButton (s). For the first time, all QRadioButtons check false. Thus, the images for this case do not have a white dot. When the user selects any QRadioButton, then the image is converted to another image with a white dot. When I click the button, I will clear the state of the switches from the selected one to clear the check box. However, the state of the image does not change. They remain in a controlled state. The code snippet is as follows:

the code:

if(ui->radioButtonReadOnlineData->isChecked()) ui->radioButtonReadOnlineData->setChecked(false); if(ui->radioButtonSavetoDBReadOfflineData->isChecked()) ui->radioButtonSavetoDBReadOfflineData->setChecked(false); if(ui->radioButtonViewLocalData->isChecked()) ui->radioButtonViewLocalData->setChecked(false); if(ui->radioButtonDateRange->isChecked()) ui->radioButtonDateRange->setChecked(false); if(ui->radioButtonAll->isChecked()) ui->radioButtonAll->setChecked(false); 

Images for each of the QRadioButtons are set as follows:

the code:

 ui->radioButtonAll->setStyleSheet( "QRadioButton::indicator::checked { image: url(:/Resources/radio-btn-selected.png);}" "QRadioButton::indicator::unchecked {image: url(:/Resources/radio-btn-unselected.png);}" ); 

Any tips on why QRradioButton images are not being updated. Thank you

+6
source share
2 answers

Your problem is most likely related to

setAutoExclusive (BOOL)

By default, all buttons of the same parent behave as if they were part of the same exclusive button group. By selecting one of them, you cannot return to the fact that all buttons are not checked.

The workaround is to find out which button is checked, and for this button do the following

 theSelectedButton->setAutoExclusive(false); thsSelectedButton->setChecked(false); theSelectedButton->setAutoExclusive(true); 

Take a look at these links for more information:

http://developer.qt.nokia.com/forums/viewthread/5482

http://www.qtforum.org/article/19619/qradiobutton-setchecked-bug.html

+11
source

Make sure your resource file looks like this:

 <qresource> <file>Resources/radio-btn-selected.png</file> <file>Resources/radio-btn-unselected.png</file> </qresource> 

And that it is correctly included in your application.

  • Or include .qrc in your .pro file with
  RESOURCES = myresource.qrc 
  • either create an external binary resource file and then register it at run time with
 QResource::registerResource("/path/to/myresource.rcc"); 
  • Or, if you use a constructor, you can do something like this .
0
source

Source: https://habr.com/ru/post/908949/


All Articles