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. QDialog - closeEvent not triggered (bug?)
QtWS25 Last Chance

QDialog - closeEvent not triggered (bug?)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views
  • 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    Hi,

    I want to fire closeEvent on my custom QDialog, so I re-implemented it, It is triggered when I press the "X" close windows sign, but not when I press "ESC" on my keyboard, I thought ESC was supposed to do the same thing as pressing X in this context, am I wrong? I want to fire an event "are you sure you want to quit" and it needs to fire all the time when the windows is closed..

    Thank you


    Free Indoor Cycling Software - https://maximumtrainer.com

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

      Hi there,

      I don't think it is a bug but a design decision. Pressing ESC causes the dialog to call the reject() function. The reject(), accept() and done() functions explicitly bypass the closeEvent().

      From the "docs:":http://qt-project.org/doc/qt-4.8/qdialog.html#escape-key

      bq. In order to modify your dialog's close behavior, you can reimplement the functions accept(), reject() or done(). The closeEvent() function should only be reimplemented to preserve the dialog's position or to override the standard close or reject behavior.

      Hope it helps.
      H.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximus
        wrote on last edited by
        #3

        Thanks this helped, I was doing trial/error for the past 15minutes..

        Fixed with this if you want ESC == Close window behavior

        @void WorkoutDialog::reject() {
        sureYouWantToQuit();
        }

        void WorkoutDialog::closeEvent(QCloseEvent *event) {
        sureYouWantToQuit();
        }@


        Free Indoor Cycling Software - https://maximumtrainer.com

        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