How to keep QListWidget focus policy to Qt::NoFocus after editing an item.

  • Hello everyone,

    I am new to Qt Programming, so please forgive me if I am asking something silly :P
    I have a QListWidget with some QListWidgetItems attached. I use QListWidget::setFocusPolity(Qt::NoFocus) in order to disable focus on the list. I also have a button that calls QListWidget::editItem() when I click it. When I click the button the QListWidget regains focus automatically(look like Qt does it internally in order to edit the item). The problem is that I don't know how to unset the focus after editing the item. I tried to connect the signal itemChanged(QListWidgetItem*) to a slot that changes the current focus from QListWidget to my main Window widget but this works only if make changes on the QListWidgetItem. If I click the button but then press Esc without changing the text of the QListWidgetItem then the itemChanged() signal is not emitted. So, my question is the following: Is there some kind of "editingFinished" signal/event emitted after editing a QListWidgetItem?

    Thanks in advance!


  • Maybe "QAbstractItemDelegate::closeEditor() ": can help you. You can connect it like this:


  • Thanks mate! It works!
    Although if finish editing an item by clicking another item on the list it won't work. (it only works if i press ENTER , ESC etc) But that's not a problem, in that case I can catch the itemClicked() signal and reset the focus. Thanks for help dude!


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.