【问题标题】:Connect a combox with a slider使用滑块连接组合框
【发布时间】:2012-08-23 14:03:17
【问题描述】:

我正在尝试将 qcombobox 与 qwtslider 连接,并且我在组合框上有两个选项,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

【问题讨论】:

    标签: qt slider qwt qcombobox


    【解决方案1】:

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

    【讨论】:

    • 这样我得到了planevolume::currentIndexPixel()' and multiple definition of planevolume::currentIndexMM()'的多个定义
    • 我试过 void activate(int index) 和 void currentIndexChanged(int index) 但我知道它们是受保护的......
    • 我想我会使用两个按钮,因为我认为这会让我的工作更轻松。
    • 你提到的那些受保护的成员是信号。
    • 我会在你有 currentIndex(1) 的地方使用 setCurrentIndex(1)。虽然我对你的连接语句有点困惑。
    猜你喜欢
    • 2021-12-21
    • 2017-06-01
    • 2011-09-27
    • 2012-03-02
    • 2017-01-07
    • 2017-04-09
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多