将组合框与滑块连接

时间:2012-08-23 14:03:18

标签: qt slider qwt qcombobox

我正在尝试将qcombobox与qwtslider连接,我在combox上有两个选项,mm和pixel。我想在选择该选项时将比例更改为像素或毫米。我创建了一些作为插槽工作的函数,它们是:

void planevolume::mm()
{
      ui->Slider->setRange(xmin, xmax/(256/3), 1.0/(256/3));
      ui->Slider->setScale(xmin, (xmax+1)/(256/3), ((xmax+1)/16)/(256/3));
      connect(ui->Slider, SIGNAL(valueChanged(double)), ui->lcdNumber, SLOT(display(double)));
}

void planevolume::pixel()
{
      ui->Slider->setRange(xmin, xmax, 1.0);
      ui->Slider->setScale(xmin, xmax+1, (xmax+1)/16);
      connect(ui->Slider, SIGNAL(valueChanged(double)), ui->lcdNumber, SLOT(display(double)));
}

我认为我可以使用连接盒中的信号连接它们。我的连接盒是这样的:

  ui->comboBox->insertItem( 1, QString("pixel"));
  ui->comboBox->insertItem( 2, QString("mm"));

他们创建了一个可供选择的插槽:

void planevolume::currentIndexPixel()
{
    ui->comboBox->currentIndex(1);
}

void planevolume::currentIndexMM()
{
    ui->comboBox->currentIndex(2);
}

他们像这样连接它:

connect(this, SIGNAL(currentIndexPixel()),ui->Slider, SLOT(pixel()));
connect(this, SIGNAL(currentIndexMM()),ui->Slider, SLOT(mm()));

但是我得到了这样的错误,而且我不确定我做错了什么:

error: no matching function for call to ‘QComboBox::currentIndex(int)’
/usr/include/qt4/QtGui/qcombobox.h:184: note: candidates are: int QComboBox::currentIndex() const

1 个答案:

答案 0 :(得分:1)

我认为您的意思是在setCurrentIndex()currentIndex()函数中使用currentIndexPixel而不是currentIndexMM