![](/img/trans.png)
[英]Qt attaching itemChanged signal to QStandardItem doesn't work
[英]Blocking signal one time in Qt doesn't work correctly
嗨,我有以下代碼:
void MainWindow::on_listWidgetNotes_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)//Test!
{
if(current != NULL)
{
ui->plainTextEditContent->setEnabled(true);
change = false;
if(isModified)
{
auto reply = QMessageBox::question(this, "Test", "Do you want save changes?", QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
if (reply == QMessageBox::Yes) on_pushButtonSave_clicked();
else if(reply == QMessageBox::No) notes.closeFile();
else
{
//ui->listWidgetNotes->blockSignals(true);
ui->listWidgetNotes->setCurrentItem(previous);
//ui->listWidgetNotes->blockSignals(false);
return;
}
}
isModified = false;
this->setWindowTitle(current->text()+" - VfNotes 1.0");
ui->plainTextEditContent->setPlainText(notes.openFile(current->text()));
}
}
在指定情況下,代碼必須顯示消息框,並在選擇取消按鈕后將焦點放在上一個項目上。
但是setCurrentItem
使用此消息框再次調用on_listWidgetNotes_currentItemChanged
。 使用blockSignals
焦點不會再回到上一個元素。 如何在單擊取消后將焦點設置在上一個項目上,而不再次調用on_listWidgetNotes_currentItemChanged
?
因此,如果這是在選擇更改時調用的插槽,則改為調用該插槽,創建另一個插槽,然后從那里調用此函數。現在,此新插槽將具有上一個項目,並且從那里開始返回一本書,而不是void表示按下了取消鍵,然后再次調用setCurrentItem ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.