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. Building a QInputDialog with only the "ok" button
Forum Updated to NodeBB v4.3 + New Features

Building a QInputDialog with only the "ok" button

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.1k Views 2 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.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    Hi. I'm trying to build a QInputDialog with only the "ok" button. My plan so far is to set the Dialogbox as one with no buttons, then add an extra QPushButton inside it.

        QInputDialog passwordBox(this, Qt::Dialog);
        //Create custom dialogbox with greater control.
        bool ok;
    
        //Remove the cancel button, the question mark, and change the text to something we can use
        passwordBox.setOption(QInputDialog::NoButtons); //Remove all buttons
        //Add button back, to be implemented later
    
        passwordBox.setWindowFlag(Qt::WindowContextHelpButtonHint, false);
        passwordBox.setWindowTitle("Input password:");
        passwordBox.setLabelText("Input password:");
        passwordBox.exec();
    

    I am wondering whether there is a method that is easier and would only require destroying the "cancel" button. I looked into the matter and found this alternate method which seems to make the buttons invisible. But this is for Qt4 and it seems to take various additional steps.

    Is there a method that is easier and would only require destroying the "cancel" button?

    Pl45m4P M 2 Replies Last reply
    0
    • Dummie1138D Dummie1138

      @Pl45m4 I want to build a QInputDialog with only the "ok" button, which would act in the same way any other Ok button in QInputDialog would. The reason is for the QInputDialog to act as a password input.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #4

      @Dummie1138 said in Building a QInputDialog with only the "ok" button:

      @Pl45m4 I want to build a QInputDialog with only the "ok" button, which would act in the same way any other Ok button in QInputDialog would. The reason is for the QInputDialog to act as a password input.

      Either accept that QInputDialog provides these buttons and functionality or create your own, custom dialog from QDialog. Then you have full control over the layout and you can basically do what you want.
      BTW: Even if you remove the cancel button, the action when pressing ESC on your keyboard, for example, stays the same. It will reject() the dialog.


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

      ~E. W. Dijkstra

      Dummie1138D 1 Reply Last reply
      1
      • Dummie1138D Dummie1138

        Hi. I'm trying to build a QInputDialog with only the "ok" button. My plan so far is to set the Dialogbox as one with no buttons, then add an extra QPushButton inside it.

            QInputDialog passwordBox(this, Qt::Dialog);
            //Create custom dialogbox with greater control.
            bool ok;
        
            //Remove the cancel button, the question mark, and change the text to something we can use
            passwordBox.setOption(QInputDialog::NoButtons); //Remove all buttons
            //Add button back, to be implemented later
        
            passwordBox.setWindowFlag(Qt::WindowContextHelpButtonHint, false);
            passwordBox.setWindowTitle("Input password:");
            passwordBox.setLabelText("Input password:");
            passwordBox.exec();
        

        I am wondering whether there is a method that is easier and would only require destroying the "cancel" button. I looked into the matter and found this alternate method which seems to make the buttons invisible. But this is for Qt4 and it seems to take various additional steps.

        Is there a method that is easier and would only require destroying the "cancel" button?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #2

        @Dummie1138 said in Building a QInputDialog with only the "ok" button:

        My plan so far is to set the Dialogbox as one with no buttons, then add an extra QPushButton inside it.

        What's the point? What should this extra/new button do?
        Consider using QDialog instead, if you need other "features".

        But this is for Qt4 and it seems to take various additional steps.

        Why do you think that? AFAICS the example on SO is tagged with Qt5 and as long as stuff wasn't removed in Qt5/6 it should still work.


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

        ~E. W. Dijkstra

        Dummie1138D 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @Dummie1138 said in Building a QInputDialog with only the "ok" button:

          My plan so far is to set the Dialogbox as one with no buttons, then add an extra QPushButton inside it.

          What's the point? What should this extra/new button do?
          Consider using QDialog instead, if you need other "features".

          But this is for Qt4 and it seems to take various additional steps.

          Why do you think that? AFAICS the example on SO is tagged with Qt5 and as long as stuff wasn't removed in Qt5/6 it should still work.

          Dummie1138D Offline
          Dummie1138D Offline
          Dummie1138
          wrote on last edited by
          #3

          @Pl45m4 I want to build a QInputDialog with only the "ok" button, which would act in the same way any other Ok button in QInputDialog would. The reason is for the QInputDialog to act as a password input.

          Pl45m4P 1 Reply Last reply
          0
          • Dummie1138D Dummie1138

            @Pl45m4 I want to build a QInputDialog with only the "ok" button, which would act in the same way any other Ok button in QInputDialog would. The reason is for the QInputDialog to act as a password input.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #4

            @Dummie1138 said in Building a QInputDialog with only the "ok" button:

            @Pl45m4 I want to build a QInputDialog with only the "ok" button, which would act in the same way any other Ok button in QInputDialog would. The reason is for the QInputDialog to act as a password input.

            Either accept that QInputDialog provides these buttons and functionality or create your own, custom dialog from QDialog. Then you have full control over the layout and you can basically do what you want.
            BTW: Even if you remove the cancel button, the action when pressing ESC on your keyboard, for example, stays the same. It will reject() the dialog.


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

            ~E. W. Dijkstra

            Dummie1138D 1 Reply Last reply
            1
            • Dummie1138D Dummie1138 has marked this topic as solved on
            • Dummie1138D Dummie1138

              Hi. I'm trying to build a QInputDialog with only the "ok" button. My plan so far is to set the Dialogbox as one with no buttons, then add an extra QPushButton inside it.

                  QInputDialog passwordBox(this, Qt::Dialog);
                  //Create custom dialogbox with greater control.
                  bool ok;
              
                  //Remove the cancel button, the question mark, and change the text to something we can use
                  passwordBox.setOption(QInputDialog::NoButtons); //Remove all buttons
                  //Add button back, to be implemented later
              
                  passwordBox.setWindowFlag(Qt::WindowContextHelpButtonHint, false);
                  passwordBox.setWindowTitle("Input password:");
                  passwordBox.setLabelText("Input password:");
                  passwordBox.exec();
              

              I am wondering whether there is a method that is easier and would only require destroying the "cancel" button. I looked into the matter and found this alternate method which seems to make the buttons invisible. But this is for Qt4 and it seems to take various additional steps.

              Is there a method that is easier and would only require destroying the "cancel" button?

              M Offline
              M Offline
              mpergand
              wrote on last edited by mpergand
              #5

              @Dummie1138 said in Building a QInputDialog with only the "ok" button:

              Is there a method that is easier and would only require destroying the "cancel" button?

              Unfortunately, the inner QDialogButtonBox is not accessible directly, so some hacky stuff is needed:

              QInputDialog in;
                  in.setInputMode(QInputDialog::TextInput);
                  in.setTextEchoMode(QLineEdit::Password);
                  qDebug()<<in.children();
                  in.show();  // needed for buttonBox to exist
              
                  auto box=in.findChild<QDialogButtonBox*>();
                    if(box)
                        {
                          box->setStandardButtons(QDialogButtonBox::Ok);
                        }
                    in.exec();
              

              As @Pl45m4 said, better to create your own custom dialog.

              1 Reply Last reply
              1
              • Pl45m4P Pl45m4

                @Dummie1138 said in Building a QInputDialog with only the "ok" button:

                @Pl45m4 I want to build a QInputDialog with only the "ok" button, which would act in the same way any other Ok button in QInputDialog would. The reason is for the QInputDialog to act as a password input.

                Either accept that QInputDialog provides these buttons and functionality or create your own, custom dialog from QDialog. Then you have full control over the layout and you can basically do what you want.
                BTW: Even if you remove the cancel button, the action when pressing ESC on your keyboard, for example, stays the same. It will reject() the dialog.

                Dummie1138D Offline
                Dummie1138D Offline
                Dummie1138
                wrote on last edited by
                #6

                @Pl45m4 Thank you. I presume when you suggested building a custom QDialog class, that involves stuffing a QLineEdit into the QDialog?

                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