Show message
-

Can i create this kind of message with qt (without a boutton of confirmation like QMessageBox)
thank you -
Hi
But if there is no button to get rid of the Message,
how should user then close it ?
Also, Do you want the round corner etc also or was it just to show "without buttons" ? -
Hi
But if there is no button to get rid of the Message,
how should user then close it ?
Also, Do you want the round corner etc also or was it just to show "without buttons" ? -
@mrjj in fact I want when I press the button there is a message that will be displayed for 5s after it closes automatically
-
@mrjj in fact I want when I press the button there is a message that will be displayed for 5s after it closes automatically
-
@mrjj in fact I want when I press the button there is a message that will be displayed for 5s after it closes automatically
@jackfr
Hi
Small sample to get you going.void ShowMsg(QWidget *parent, QString msg ) { QLabel *msgbox = new QLabel (parent); msgbox->setGeometry(100, 100, 300, 200); // size of the popup msgbox->setText(msg); msgbox->setStyleSheet("margin-left: 0px; border: 2px solid black; border-radius: 12px; background: #686a69; color: white;"); msgbox->show(); // this fire a timer after 5 secs and close and deletes the qlabel. QTimer::singleShot(5 * 1000, parent, [msgbox]() { msgbox->close(); msgbox->deleteLater(); }); } void EditorMainWin::on_pushButton_pressed() { ShowMsg(this, "im a line to be shown"); }gives you

-
Just a little note to what @mrjj posted. It's always a good idea to tie timer connections (any other too actually) to objects the slot operates on. Otherwise you're running a risk of calling methods on objects that don't exist anymore. If something deletes the message box before the timeout, the lambda would crash, so it's better to tie the connection to
msgboxand notparent.Also, deleting a widget will close it first anyway, so in this case you can shorten it to:
QTimer::singleShot(5 * 1000, msgbox, &QWidget::deleteLater); -
@jackfr
Hi
Small sample to get you going.void ShowMsg(QWidget *parent, QString msg ) { QLabel *msgbox = new QLabel (parent); msgbox->setGeometry(100, 100, 300, 200); // size of the popup msgbox->setText(msg); msgbox->setStyleSheet("margin-left: 0px; border: 2px solid black; border-radius: 12px; background: #686a69; color: white;"); msgbox->show(); // this fire a timer after 5 secs and close and deletes the qlabel. QTimer::singleShot(5 * 1000, parent, [msgbox]() { msgbox->close(); msgbox->deleteLater(); }); } void EditorMainWin::on_pushButton_pressed() { ShowMsg(this, "im a line to be shown"); }gives you
