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. Disable standard button within QDialogButtonBox
QtWS25 Last Chance

Disable standard button within QDialogButtonBox

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 24.9k 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.
  • K Offline
    K Offline
    kbt90
    wrote on last edited by
    #1

    Hello -

    I have a QDialogButtonBox that contains 2 standard buttons: QDialogButtonBox::Ok and QDialogButtonBox::Cancel.

    I would like to be able to disable the okay button if certain conditions aren't met. However upon doing the following:

    @QDialogButtonBox::Ok.setEnabled (false);@

    I get an error message:
    error: request for member 'setEnabled' in (QDialogButtonBox::StandardButton)1024u', which is of non-class type 'QDialogButtonBox::StandardButton'.

    So, if I use a QDialogButtonBox, I cannot use setEnabled, but is there and equivalent for this?

    Thanks,
    Kate

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Hi Kate,

      you should be able to define the standard buttons through this "constructor":http://doc.qt.nokia.com/4.7/qdialogbuttonbox.html#QDialogButtonBox-3
      That should do the trick as long as you do not have to switch it later during runtime, I guess.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kbt90
        wrote on last edited by
        #3

        I created this dialog using Qt Designer, so I don't actually have a constructor. How can I define the standard buttons without a constructor?

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          you can drag a QDialogButtonBox in your form and then set the flags in the properties on the right.
          Scroll down almost to the bottom and you'll see Standardbuttons. just check the choices you want.

          About your question to set your ok button not enabled while your cancel buttons stays active:
          you used the OK enum and that doesn't represent the okbutton, it's just a flag like you can set in QT Designer as explained before.

          If I were you I would use 2 different pushbuttons one with OK and one with Cancel on it. Then you can enable/disable them seperately.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            From within your dialog source file you can do something like this:

            @
            myButtonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
            @

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            3
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              Thanks, didn't know that. You are the man ;)

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                ZapB
                wrote on last edited by
                #7

                No problem. There's so many aspects to Qt now that it is virtually impossible for anyone to know all of it in detail. But that's why I like these forums and wiki, there's always some new little trick or technique to be found :-)

                Nokia Certified Qt Specialist
                Interested in hearing about Qt related work

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kbt90
                  wrote on last edited by
                  #8

                  Super! Thank you all!

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    drumboy354
                    wrote on last edited by
                    #9

                    if anybody cares the way you can do it with the QDialogButtonBox widget is:

                    (assuming your button box is called "buttonBox"):

                    flag = false
                    self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(flag)

                    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