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. what determines the order of the pushbuttons in a dialog?

what determines the order of the pushbuttons in a dialog?

Scheduled Pinned Locked Moved Solved General and Desktop
dialogpushbutton
6 Posts 4 Posters 726 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.
  • J Offline
    J Offline
    jdent
    wrote on 20 Mar 2024, 21:30 last edited by
    #1

    I have this code:

        QPushButton* closeButton = new QPushButton(tr("&Close"));
        QPushButton* revertButton = new QPushButton(tr("&Revert"));
        QPushButton* submitButton = new QPushButton(tr("&Submit"));
    
        submitButton->setAutoDefault(false);
        revertButton->setAutoDefault(false);
        closeButton->setDefault(true);
    
        connect(closeButton, &QPushButton::clicked, this, &PasswordDetailsDlg::close);
        connect(revertButton, &QPushButton::clicked, this, &PasswordDetailsDlg::revert);
        connect(submitButton, &QPushButton::clicked, this, &PasswordDetailsDlg::submit);
    
        QDialogButtonBox* buttonBox = new QDialogButtonBox;
        buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
        buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
        buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
    
        return buttonBox;
    

    But instead of placing the submit button first, then the revert then the close, it places the revert, then the submit and then the close. What order is that???

    How can we control the order of pushbuttons in a dialog button box? Does it have to do with the roles?

    J C P 3 Replies Last reply 20 Mar 2024, 21:56
    0
    • J jdent
      20 Mar 2024, 21:30

      I have this code:

          QPushButton* closeButton = new QPushButton(tr("&Close"));
          QPushButton* revertButton = new QPushButton(tr("&Revert"));
          QPushButton* submitButton = new QPushButton(tr("&Submit"));
      
          submitButton->setAutoDefault(false);
          revertButton->setAutoDefault(false);
          closeButton->setDefault(true);
      
          connect(closeButton, &QPushButton::clicked, this, &PasswordDetailsDlg::close);
          connect(revertButton, &QPushButton::clicked, this, &PasswordDetailsDlg::revert);
          connect(submitButton, &QPushButton::clicked, this, &PasswordDetailsDlg::submit);
      
          QDialogButtonBox* buttonBox = new QDialogButtonBox;
          buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
          buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
          buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
      
          return buttonBox;
      

      But instead of placing the submit button first, then the revert then the close, it places the revert, then the submit and then the close. What order is that???

      How can we control the order of pushbuttons in a dialog button box? Does it have to do with the roles?

      P Online
      P Online
      Pl45m4
      wrote on 20 Mar 2024, 23:27 last edited by Pl45m4
      #6

      @jdent said in what determines the order of the pushbuttons in a dialog?:

      QDialogButtonBox* buttonBox = new QDialogButtonBox;
      buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
      buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
      buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
      

      The thing is, these roles make life easier, because they automatically accept or reject your dialog when being clicked. But like @JonB said, nobody forces you to use a QDialogButtonBox in your dialog. It's nice to have, but if you don't like the OS default order (on some OS "OK" is left and "Cancel" right and on some it's reversed), you can put them in a regular layout and manually handle the accept() / reject() states.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • J jdent
        20 Mar 2024, 21:30

        I have this code:

            QPushButton* closeButton = new QPushButton(tr("&Close"));
            QPushButton* revertButton = new QPushButton(tr("&Revert"));
            QPushButton* submitButton = new QPushButton(tr("&Submit"));
        
            submitButton->setAutoDefault(false);
            revertButton->setAutoDefault(false);
            closeButton->setDefault(true);
        
            connect(closeButton, &QPushButton::clicked, this, &PasswordDetailsDlg::close);
            connect(revertButton, &QPushButton::clicked, this, &PasswordDetailsDlg::revert);
            connect(submitButton, &QPushButton::clicked, this, &PasswordDetailsDlg::submit);
        
            QDialogButtonBox* buttonBox = new QDialogButtonBox;
            buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
            buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
            buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
        
            return buttonBox;
        

        But instead of placing the submit button first, then the revert then the close, it places the revert, then the submit and then the close. What order is that???

        How can we control the order of pushbuttons in a dialog button box? Does it have to do with the roles?

        J Offline
        J Offline
        JonB
        wrote on 20 Mar 2024, 21:56 last edited by JonB
        #2

        @jdent
        Yes. Have you read the description at https://doc.qt.io/qt-6/qdialogbuttonbox.html#details ? The point is it takes over the placement and styling to "conforms to the interface guidelines for that platform". The roles determine where it decides things go.

        Try all of yours with, say, QDialogButtonBox::ApplyRole at the same time, does it then just follow the order you add them?

        You realize that if you really want to control the layout yourself don't bother to use QDialogButtonBox! You don't have to, it's there to help if you want the platform to decide what it looks like.

        J 1 Reply Last reply 20 Mar 2024, 22:42
        1
        • J jdent
          20 Mar 2024, 21:30

          I have this code:

              QPushButton* closeButton = new QPushButton(tr("&Close"));
              QPushButton* revertButton = new QPushButton(tr("&Revert"));
              QPushButton* submitButton = new QPushButton(tr("&Submit"));
          
              submitButton->setAutoDefault(false);
              revertButton->setAutoDefault(false);
              closeButton->setDefault(true);
          
              connect(closeButton, &QPushButton::clicked, this, &PasswordDetailsDlg::close);
              connect(revertButton, &QPushButton::clicked, this, &PasswordDetailsDlg::revert);
              connect(submitButton, &QPushButton::clicked, this, &PasswordDetailsDlg::submit);
          
              QDialogButtonBox* buttonBox = new QDialogButtonBox;
              buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
              buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
              buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
          
              return buttonBox;
          

          But instead of placing the submit button first, then the revert then the close, it places the revert, then the submit and then the close. What order is that???

          How can we control the order of pushbuttons in a dialog button box? Does it have to do with the roles?

          C Offline
          C Offline
          ChrisW67
          wrote on 20 Mar 2024, 21:57 last edited by ChrisW67
          #3

          @jdent
          In general, QWidget::setTabOrder()
          You can do this in Qt Designer if you use Designer forms.

          Keyboard Focus in Widgets

          Edit: did not pick up you were trying to do this in a button box.

          1 Reply Last reply
          0
          • J JonB
            20 Mar 2024, 21:56

            @jdent
            Yes. Have you read the description at https://doc.qt.io/qt-6/qdialogbuttonbox.html#details ? The point is it takes over the placement and styling to "conforms to the interface guidelines for that platform". The roles determine where it decides things go.

            Try all of yours with, say, QDialogButtonBox::ApplyRole at the same time, does it then just follow the order you add them?

            You realize that if you really want to control the layout yourself don't bother to use QDialogButtonBox! You don't have to, it's there to help if you want the platform to decide what it looks like.

            J Offline
            J Offline
            jdent
            wrote on 20 Mar 2024, 22:42 last edited by
            #4

            @JonB if I don't use QDialogButtonBox what do I use instead? Just QGroupBox?

            J 1 Reply Last reply 20 Mar 2024, 22:52
            0
            • J jdent
              20 Mar 2024, 22:42

              @JonB if I don't use QDialogButtonBox what do I use instead? Just QGroupBox?

              J Offline
              J Offline
              JonB
              wrote on 20 Mar 2024, 22:52 last edited by JonB
              #5

              @jdent
              Anything you like, QGroupBox or not. (Except a dialog would not normally put its buttons in a box, but it does not stop you doing it.) Or just a layout. You are free to put whatever you want anywhere on a QDialog just like on any other widget.

              1 Reply Last reply
              1
              • J jdent
                20 Mar 2024, 21:30

                I have this code:

                    QPushButton* closeButton = new QPushButton(tr("&Close"));
                    QPushButton* revertButton = new QPushButton(tr("&Revert"));
                    QPushButton* submitButton = new QPushButton(tr("&Submit"));
                
                    submitButton->setAutoDefault(false);
                    revertButton->setAutoDefault(false);
                    closeButton->setDefault(true);
                
                    connect(closeButton, &QPushButton::clicked, this, &PasswordDetailsDlg::close);
                    connect(revertButton, &QPushButton::clicked, this, &PasswordDetailsDlg::revert);
                    connect(submitButton, &QPushButton::clicked, this, &PasswordDetailsDlg::submit);
                
                    QDialogButtonBox* buttonBox = new QDialogButtonBox;
                    buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
                    buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
                    buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
                
                    return buttonBox;
                

                But instead of placing the submit button first, then the revert then the close, it places the revert, then the submit and then the close. What order is that???

                How can we control the order of pushbuttons in a dialog button box? Does it have to do with the roles?

                P Online
                P Online
                Pl45m4
                wrote on 20 Mar 2024, 23:27 last edited by Pl45m4
                #6

                @jdent said in what determines the order of the pushbuttons in a dialog?:

                QDialogButtonBox* buttonBox = new QDialogButtonBox;
                buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
                buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
                buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
                

                The thing is, these roles make life easier, because they automatically accept or reject your dialog when being clicked. But like @JonB said, nobody forces you to use a QDialogButtonBox in your dialog. It's nice to have, but if you don't like the OS default order (on some OS "OK" is left and "Cancel" right and on some it's reversed), you can put them in a regular layout and manually handle the accept() / reject() states.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                1
                • J jdent has marked this topic as solved on 21 Mar 2024, 14:12

                4/6

                20 Mar 2024, 22:42

                • Login

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