Building a QInputDialog with only the "ok" button
-
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?
-
@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.
@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
QInputDialogprovides these buttons and functionality or create your own, custom dialog fromQDialog. 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 willreject()the dialog. -
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?
@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 usingQDialoginstead, 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
Qt5and as long as stuff wasn't removed in Qt5/6 it should still work. -
@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 usingQDialoginstead, 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
Qt5and as long as stuff wasn't removed in Qt5/6 it should still work.@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.
-
@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.
@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
QInputDialogprovides these buttons and functionality or create your own, custom dialog fromQDialog. 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 willreject()the dialog. -
D Dummie1138 has marked this topic as solved on
-
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?
@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.
-
@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
QInputDialogprovides these buttons and functionality or create your own, custom dialog fromQDialog. 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 willreject()the dialog.@Pl45m4 Thank you. I presume when you suggested building a custom QDialog class, that involves stuffing a QLineEdit into the QDialog?