Qt 5.5 使用 C++,从 ComboBox 中删除和删除项目也删除了项目之前的所有项目
Qt 5.5 using C++, removing and item from ComboBox is removing all items before the item as well
处理一个程序,其中 6 个组合框具有相关数据,一旦索引被 selected,其他人不应该能够 select 它,因此我只是将它从其他人的索引,但实际上它出于某种原因正在删除索引加上它之前的每个索引。知道为什么吗?
void AssignStatsWindow::on_comboBox_currentIndexChanged()
{
ui->comboBox_2->removeItem(ui->comboBox->currentIndex()); //these should remove 1 index but removes many
ui->comboBox_3->removeItem(ui->comboBox->currentIndex());
ui->comboBox_4->removeItem(ui->comboBox->currentIndex());
ui->comboBox_5->removeItem(ui->comboBox->currentIndex());
ui->comboBox_6->removeItem(ui->comboBox->currentIndex());
for (int i = ui->comboBox->count(); i >= 0; --i) //removes all but newly selected index, seems to be working fine
{
if (i != ui->comboBox->currentIndex()) {
ui->comboBox->removeItem(i);
}
}
}
comboBox
是有indexChanged
触发代码的,comboBox_2
到6是其他需要调整的,是'over-removing'索引。一旦我让第一个正常工作,就应该很容易为 comboBox
的其余部分构建 indexChanged
的其余部分。任何帮助将不胜感激。
Removes the item at the given index from the combobox. This will update the current index if the index is removed.
in practice it is removing the index plus every index before it for some reason. Any idea why?
似乎在响应 currentIndexChanged
信号的插槽中执行删除项目的工作。上面的文档指出删除一个项目将改变组合框的当前索引,这将导致插槽被多次触发,从而删除许多项目。
处理一个程序,其中 6 个组合框具有相关数据,一旦索引被 selected,其他人不应该能够 select 它,因此我只是将它从其他人的索引,但实际上它出于某种原因正在删除索引加上它之前的每个索引。知道为什么吗?
void AssignStatsWindow::on_comboBox_currentIndexChanged()
{
ui->comboBox_2->removeItem(ui->comboBox->currentIndex()); //these should remove 1 index but removes many
ui->comboBox_3->removeItem(ui->comboBox->currentIndex());
ui->comboBox_4->removeItem(ui->comboBox->currentIndex());
ui->comboBox_5->removeItem(ui->comboBox->currentIndex());
ui->comboBox_6->removeItem(ui->comboBox->currentIndex());
for (int i = ui->comboBox->count(); i >= 0; --i) //removes all but newly selected index, seems to be working fine
{
if (i != ui->comboBox->currentIndex()) {
ui->comboBox->removeItem(i);
}
}
}
comboBox
是有indexChanged
触发代码的,comboBox_2
到6是其他需要调整的,是'over-removing'索引。一旦我让第一个正常工作,就应该很容易为 comboBox
的其余部分构建 indexChanged
的其余部分。任何帮助将不胜感激。
Removes the item at the given index from the combobox. This will update the current index if the index is removed.
in practice it is removing the index plus every index before it for some reason. Any idea why?
似乎在响应 currentIndexChanged
信号的插槽中执行删除项目的工作。上面的文档指出删除一个项目将改变组合框的当前索引,这将导致插槽被多次触发,从而删除许多项目。