|
这个问题是因为 on_listWidget_currentRowChanged 这个槽函数在界面加载完毕之后会立马触发一次, currentIndex 会从 -1 变为 0,所以有一次函数的调用,你把 主界面上的 Index 传到 dialog ,然后在 on_listWidget_currentRowChanged 这个函数里面 做这样一个判断
if(currentRow == this->currentIndex)
{
ui->stackedWidget->setCurrentIndex(currentRow);
ui->listWidget->setCurrentRow(currentRow);
}
else
{
ui->stackedWidget->setCurrentIndex(this->currentIndex);
ui->listWidget->setCurrentRow(this->currentIndex);
}
this-> currentIndex 就是在dialog 构造函数里面接收的来自 mainwindow 的 index 参数
Dialog:: Dialog(QWidget *parent, int index) :
QDialog(parent),
ui(new Ui:: Dialog),currentIndex(index)
{
ui->setupUi(this);
}
如此这个问题就可以得到解决 |
|