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. Help with QButtonBox
Qt 6.11 is out! See what's new in the release blog

Help with QButtonBox

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.1k 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.
  • N Offline
    N Offline
    ningu
    wrote on last edited by
    #1

    Hi,

    I'm new to Qt.

    I have a QDialog with a QButtonBox that has a Save, Cancel and Open buttons. I've read the documentation for the QButtonBox, but I just can't figure out how to manage the buttons events. I know I can manage the accepted() and cancelled() events, but since Open and Save buttons are both 'accepting' I don't know where to put the code for each one of them. Any pointers?

    I've been searching but I just can't find any answers to this problem. I'm stuck and I would very much appreciate your help.

    Thanks.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nikoko
      wrote on last edited by
      #2

      You can use the signal :
      void clicked ( QAbstractButton * button )
      to know what button you activate by clicking

      1 Reply Last reply
      0
      • N Offline
        N Offline
        ningu
        wrote on last edited by
        #3

        Thanks. I tried that, but I had problems figuring out how to know what button sent the signal. I finally found button->text() to be the closest hit, but I'm not sure if that's the best way to do it. Is there a better (correct) way to find out about the sender?

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nikoko
          wrote on last edited by
          #4

          Use sender () function which return which object send the signal.
          Example :
          @
          void xxxx:mySlot ()
          {
          QPushButton * pb = dynamic_cast <QPushButton *>( sender ());

          if (pb == buttonOk)
          ...
          }
          @

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            You can use the "clicked signal":http://qt-project.org/doc/qt-4.8/qdialogbuttonbox.html#clicked signal from QDialogButtonBox:
            @
            void xxxx::onClickedButtonSignal(QAbstractButton * button)
            {
            QDialogButtonBox::StandardButton stdButton = _dialogButtonBox.standardButton(button);
            switch (stdButton) {
            case QDialogButtonBox::Ok:
            ...
            break;
            // etc...
            }
            }
            @

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • N Offline
              N Offline
              ningu
              wrote on last edited by
              #6

              _dialogButtonBox was giving me an error because it's not the name of my instance and took me a while to find out that the right code for me:
              @QDialogButtonBox::StandardButton stdButton = ui->buttonBox->standardButton(button);@
              As I told you, I'm new to Qt. But now I got it running. Thank you very much SGaist!

              @Nikoko: Thanks for your suggestion. I think I get what you mean, but SGaist's solution is exactly what I was looking for.

              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