Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Dialog standardButtons
Qt 6.11 is out! See what's new in the release blog

Dialog standardButtons

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 772 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.
  • P Offline
    P Offline
    PixyWitchy
    wrote on last edited by
    #1

    Hello,

    I would like to know how to get the result of which button was press.
    For example I have yes, no , ok, cancel. If I click on no I know that it is rejected but I don't know if the user press no or cancel.

    Thank you,

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Nifiro
      wrote on last edited by Nifiro
      #2
      Dialog {
          id: dialog
          standardButtons: Dialog.Yes | Dialog.No | Dialog.Ok | Dialog.Cancel
      
          Connections {
              target: dialog.footer
              onClicked: {
                  if (button.text === dialog.standardButton(Dialog.Cancel).text)
                      console.log("Cancel clicked")
                  else if (button.text === dialog.standardButton(Dialog.No).text)
                      console.log("No clicked")
              }
          }
      }
      

      It looks ugly, but it works

      B 1 Reply Last reply
      0
      • N Nifiro
        Dialog {
            id: dialog
            standardButtons: Dialog.Yes | Dialog.No | Dialog.Ok | Dialog.Cancel
        
            Connections {
                target: dialog.footer
                onClicked: {
                    if (button.text === dialog.standardButton(Dialog.Cancel).text)
                        console.log("Cancel clicked")
                    else if (button.text === dialog.standardButton(Dialog.No).text)
                        console.log("No clicked")
                }
            }
        }
        

        It looks ugly, but it works

        B Offline
        B Offline
        Bob64
        wrote on last edited by Bob64
        #3

        @Nifiro I am away from my computer at the moment but I believe it is possible to compare button directly with standardButton(Dialog.Cancel) etc.

        i.e.

        if (button === dialog.standardButton(Dialog.Cancel)) { 
           ...
        

        I seem to recall having to do this inside an explicit DialogButtonBox though. I don't see standardButton() defined as a method on Dialog, though I am stuck with using 5.9.6 at the moment and maybe it has changed since.

        Edit: Just looked at more recent doc and I still don't see standardButton() defined on Dialog itself, but maybe it is available but undocumented?

        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