QMessageBox and QInputDialog
-
Hi,
For Input Dialog default ok,cancel buttons will come,I am trying to disable that buttons, but i am failing to do it.
I have tried for QMessageBox by using "setStandardButtons(0)", it is not working, when I am trying to use it,it is hanging there.
I am attaching code:
QMessageBox *box=new QMessageBox;
box->setText("Clicked albel");
box->setStandardButtons(0);
QTimer::singleShot(2000, box, SLOT(close()));
box->exec();
In this case its not closing,according to timer I have written in my code,it is hanging after executing messagebox.
In case of QInputDialog, I have use used setOption(QInputDialog::NoButtons), its not working@DivyaMuthyala said in QMessageBox and QInputDialog:
Hi,
For Input Dialog default ok,cancel buttons will come,I am trying to disable that buttons, but i am failing to do it.
I have tried for QMessageBox by using "setStandardButtons(0)", it is not working, when I am trying to use it,it is hanging there.
I am attaching code:
QMessageBox *box=new QMessageBox;
box->setText("Clicked albel");
box->setStandardButtons(0);
QTimer::singleShot(2000, box, SLOT(close()));
box->exec();
In this case its not closing,according to timer I have written in my code,it is hanging after executing messagebox.
In case of QInputDialog, I have use used setOption(QInputDialog::NoButtons), its not workingIn that case a little bit more effort is required. You can installEventFilter on the messagebox. Then inside
eventFilter
watch for that messagebox'sQEvent::Close
event. This event is triggered when you clickX
. Once triggered you canaccept
orreject
the messagebox.QMessageBox *msg = new QMessageBox(this); msg->setObjectName("MessageBox"); msg->installEventFilter(this); msg->setStandardButtons(0); msg->exec(); bool MainWindow::eventFilter(QObject *o, QEvent *e) { if(o->objectName()=="MessageBox") if(e->type()==QEvent::Close) { QMessageBox *box = qobject_cast<QMessageBox*>(o); box->accept(); // accept or reject closes the message box } return QMainWindow::eventFilter( o, e); }
-
Hi,
Here I want to store text in string whatever enterd in linedit,how can i do that?
@DivyaMuthyala said in QMessageBox and QInputDialog:
Hi,
Here I want to store text in string whatever enterd in linedit,how can i do that?
Try textValue after
exec
. -
You can create your own messageBox inheriting from dialog with appropriate design. You can customise with your own stuff. We can send that dialog code offline if you share your email id.
-
Hi,
divyamuthyala755@gmail.com
Thankyou -
Hi,
After Now I am able to get text from input dialog, now how to close input dialog by pressing enter key.
Thanks in advance.
-
Hi,
After Now I am able to get text from input dialog, now how to close input dialog by pressing enter key.
Thanks in advance.
@DivyaMuthyala Well, documentation: http://doc.qt.io/qt-5/qmessagebox.html
See "Default and Escape Keys" there. -
Hi,
Now My QInputDialog is not closing with Enter Key.
Can anyone please give me solution. -
Hi,
Now My QInputDialog is not closing with Enter Key.
Can anyone please give me solution.@DivyaMuthyala Did you check the link I posted?
-
Hi,
Yes I have checked , its working for messagebox but not for inputdialog. -
Hi,
Yes I have checked , its working for messagebox but not for inputdialog.@DivyaMuthyala Since QInputDialog is derived from QDialog you should read http://doc.qt.io/qt-5/qdialog.html
"Default Button". -
Hi,
Yes I have checked , its working for messagebox but not for inputdialog.Hi.
This is one of the tricky methods.
QInputDialog dlg(this); dlg.setWindowTitle(tr("QInputDialog::getText()")); dlg.setLabelText(tr("User name:")); dlg.setTextValue(QDir::home().dirName()); dlg.setOption(QInputDialog::NoButtons); dlg.open(); QLineEdit *lineEdit = dlg.findChild<QLineEdit *>(); if (lineEdit) connect(lineEdit, &QLineEdit::returnPressed, [&dlg](){ dlg.accept(); }); if (dlg.exec() == QDialog::Accepted) qDebug() << dlg.textValue();
-
Hi,
Can we create QInputDialog with only one "ok" button???
-
Hi,
Can we create QInputDialog with only one "ok" button???
@DivyaMuthyala Maybe you can. But the documentation says:
"Escape Key
If the user presses the Esc key in a dialog, QDialog::reject() will be called. This will cause the window to close: The close event cannot be ignored."
That means: even if there is no Cancel button the user will still be able to use Esc key to close the dialog. Why do you want to remove Cancel button? -
Here I am using arm based Embeded device.
My requirement is,InputDialog should by Enter Key,not for Escape Key.
-
Here I am using arm based Embeded device.
My requirement is,InputDialog should by Enter Key,not for Escape Key.
@DivyaMuthyala You can create you own dialogs