Results 1 to 2 of 2

Thread: Popping up a QMessageBox on enter key hit for QLineEdit

  1. #1
    Join Date
    Sep 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Popping up a QMessageBox on enter key hit for QLineEdit

    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

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Popping up a QMessageBox on enter key hit for QLineEdit

    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.

Similar Threads

  1. Replies: 5
    Last Post: 17th June 2011, 09:43
  2. QMessageBox with Enter key
    By dima in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2011, 11:15
  3. QMessageBox If not enter all the variables
    By NewLegend in forum Qt Programming
    Replies: 9
    Last Post: 19th November 2010, 14:18
  4. QMessageBox not popping up
    By harishankar_b in forum Newbie
    Replies: 0
    Last Post: 13th April 2010, 06:55
  5. Popping up a dialog?
    By brcain in forum Newbie
    Replies: 4
    Last Post: 24th February 2006, 02:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.