我的单选按钮有问题。
我创建了一个带有两个单选按钮的GroupBox,并将其独占,因此当检查另一个时,将取消选中。
当我检查一个时,它连接到一个作为函数的插槽,因此它执行操作,更具体地说,更改比例并转换滑块的值。
问题是当我错误地点击了已经检查过的按钮时,因为即使它已经检查过它仍然连接到函数并且滑块的值再次更改,这是我不想要的。
这是他们的代码:
//Conect change from MM or PIXEL, making the change in the scale
connect(ui->radioButton, SIGNAL(pressed())), this, SLOT(mm()));
connect(ui->radioButton_2, SIGNAL(pressed()), this, SLOT(pixel()));
之前已经检查过,有没有办法阻止它?
我将在这里发布 mm() 和 pixel() 函数:
// Function to transform the slider scale from pixel to mm
void planevolume::mm()
{
// Set the sliders ranges and connections
// X Slider
double xvaluem=ui->Slider->value();
ui->Slider->setRange(xmin, xmax/(256.0/3.0), 1.0/(256.0/3.0));
ui->Slider->setValue(xvaluem/(256.0/3.0));
ui->Slider->setScale(xmin, (xmax+1.0)/(256.0/3.0), ((xmax+1.0)/16.0)/(256.0/3.0));
connect(ui->Slider, SIGNAL(valueChanged(double)), ui->lcdNumber, SLOT(display(double)));
// Y Slider
double yvaluem=ui->Slider_2->value();
ui->Slider_2->setRange(ymin, ymax/(512.0), 1.0/(512.0));
ui->Slider_2->setValue(yvaluem/(512.0));
ui->Slider_2->setScale(ymin, (ymax+1.0)/512.0, (((ymax+1.0)/16.0)/512.0));
connect(ui->Slider_2, SIGNAL(valueChanged(double)), ui->lcdNumber_2, SLOT(display(double)));
// Z Slider
double zvaluem=ui->Slider_3->value();
ui->Slider_3->setRange(zmin, zmax/(64.0/3.0), 1.0/(64.0/3.0));
ui->Slider_3->setValue(zvaluem/(64.0/3.0));
ui->Slider_3->setScale(zmin, (zmax+1.0)/(64.0/3.0),(((zmax+1.0)/16.0)/(64.0/3.0)));
connect(ui->Slider_3, SIGNAL(valueChanged(double)), ui->lcdNumber_3, SLOT(display(double)));
}
// Function to transform the slider scale from mm to pixel
void planevolume::pixel()
{
// Set the sliders ranges and connections
// X Slider
double xvaluep=ui->Slider->value();
ui->Slider->setRange(xmin, xmax, 1.0);
ui->Slider->setValue(xvaluep*(256.0/3.0));
ui->Slider->setScale(xmin, xmax+1.0, (xmax+1.0)/16.0);
connect(ui->Slider, SIGNAL(valueChanged(double)), ui->lcdNumber, SLOT(display(double)));
// Y Slider
double yvaluep=ui->Slider_2->value();
ui->Slider_2->setRange(ymin, ymax, 1.0);
ui->Slider_2->setValue(yvaluep*(512.0));
ui->Slider_2->setScale(ymin, ymax+1.0, (ymax+1.0)/16.0);
connect(ui->Slider_2, SIGNAL(valueChanged(double)), ui->lcdNumber_2, SLOT(display(double)));
// Z Slider
double zvaluep=ui->Slider_3->value();
ui->Slider_3->setRange(zmin, zmax, 1.0);
ui->Slider_3->setValue(zvaluep*(64.0/3.0));
ui->Slider_3->setScale(zmin, zmax+1.0, (zmax+1.0)/16.0);
connect(ui->Slider_3, SIGNAL(valueChanged(double)), ui->lcdNumber_3, SLOT(display(double)));
}