Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDialogs, closeEvent() and the Escape Key

QDialogs, closeEvent() and the Escape Key

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cuddlykittens11
    wrote on last edited by
    #1

    The "documentation here":http://qt-project.org/doc/qt-4.8/qdialog.html#escape-key leads me to believe that when I press the Escape Key (when a Dialog is open and focused), that it should trigger the "QDialog::closeEvent()" function. The only problem is that it's not. Am I misinterpreting something here?

    I want my users to be able to close the Dialog with a press of the ESC Key, but because "closeEvent()" is not triggered, it doesn't return a result from the "QDialog::exec()" method.

    Also, is there a way that I close the dialog window from the constructor? These dialogs are also supposed to be singletons.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      As far as I understand documentation this is only related to modeless dialog.
      Calling exec() means it is modal.

      Regards,
      Alex

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        [quote author="cuddlykittens11" date="1421968886"]The "documentation here":http://qt-project.org/doc/qt-4.8/qdialog.html#escape-key leads me to believe that when I press the Escape Key (when a Dialog is open and focused), that it should trigger the "QDialog::closeEvent()" function. The only problem is that it's not. Am I misinterpreting something here?

        I want my users to be able to close the Dialog with a press of the ESC Key, but because "closeEvent()" is not triggered, it doesn't return a result from the "QDialog::exec()" method.
        [/quote]

        It may be that there is a shortcut conflict with the Escape key? What are the content widgets of your dialog? Are you using the Esc key as a shortcut there?

        [quote author="cuddlykittens11" date="1421968886"]
        Also, is there a way that I close the dialog window from the constructor? These dialogs are also supposed to be singletons.[/quote]

        i don't quite understand what you are trying to do? You are calling QDialog::exec() out of a constructor? If so you shouldn't do that.

        [quote author="alex_malyu" date="1421983656"]As far as I understand documentation this is only related to modeless dialog.
        Calling exec() means it is modal.[/quote]

        i would say it's the other way around

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          [quote author="cuddlykittens11" date="1421968886"]it doesn't return a result from the "QDialog::exec()" method.[/quote]

          You are wrong here. QDialog::Rejected is returned if Esc key is pressed.

          [quote author="cuddlykittens11" date="1421968886"]
          Also, is there a way that I close the dialog window from the constructor? [/quote]

          Yes:
          @
          QTimer::singleShot(0, this, [=](){ reject(); })
          @

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cuddlykittens11
            wrote on last edited by
            #5

            Okay, I cleaned up my dialog issues. Thanks for the help!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved