I have a form with two spinboxes which must be connected because of aspect ratios for width and height. When I click on first spinbox and increase/decrease value, the other, second spinbox should change its value to be in ratio with the first spinbox. I've already done the ratio connections, but there is problem, because I connect both spinboxes on SLOT valueChanged(int) and this method block whole program because endless loop. This means that when I increase value to first spinbox, value change first for this one and then for second one which is again calling the first one.
I would like to solve this problem, so when I click on one of spinboxes, to change both values in right way without endless loop.
So there is the code:
void MainWindow::on_sbHeight_valueChanged(int arg1)
{
if (arg1 != 0) {
if (ui->radioRatio1->isChecked()) {
ui->sbWidth->setValue((arg1/8)*2);
} else if (ui->radioRatio2->isChecked()) {
ui->sbWidth->setValue((arg1/14)*3);
}
} else {
ui->sbWidth->setValue(arg1);
}
}
void MainWindow::on_sbWidth_valueChanged(int arg1)
{
if (arg1 != 0) {
if (ui->radioRatio1->isChecked()) {
ui->sbHeight->setValue((arg1/2)*8);
} else if (ui->radioRatio2->isChecked()) {
ui->sbHeight->setValue((arg1/3)*14);
}
} else {
ui->sbHeight->setValue(arg1);
}
}