PDA

View Full Version : Popping up a QMessageBox on enter key hit for QLineEdit



Thuan Seah Tan
23rd March 2012, 01:21
Hi everyone,

I am trying to have Qt to behave similar to how Windows Explorer works when you rename a folder. Say if you have a folder "ABC" and you rename another folder "DEF" to "ABC", Windows Explorer will pop up a prompt asking if you want to merge the two folders or cancel the operation and therefore reverting the change. Now in my UI, I have a treeview which represents folders that user can rename and double clicking enters the edit state. I have implemented a custom QStyledItemDelegate and in the eventFilter function, I check for enter/return key press. If the user is trying to rename a folder to something that already exists and hits enter, I pop up a QMessageBox. The problem I encounter was if the QMessageBox is not parented to anything, the QLineEdit will lose focus and revert the display text back to "DEF". Is it possible to have the QLineEdit still display "ABC" (i.e. to maintain the QLineEdit in its editing state and in the treeview I will see 2 "ABC") while popping up a message box?

Thanks for any info or suggestions.

Thuan

Spitfire
26th March 2012, 09:18
From what you've said the problem occurs only when the message box is not parented.
Why not to parent it then? Seems like a simplest solution.