From 329c770aa0b1cfeb27c9cf79427a7cd55ea97baa Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 7 Aug 2023 14:01:51 +0200 Subject: [PATCH] Use a message box with color red and a timer to click on ok after 5 secs. --- mainwindow.cpp | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 2e1943b..e6b4e79 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -160,29 +160,51 @@ void MainWindow::onAppendText(QString text, QString suffix) { QStringList lines = editText.split('\n'); for (int i=0; iupdateStatus->setPlainText(editText); + ui->updateStatus->setPlainText(editText.trimmed()); ui->updateStatus->setEnabled(true); } void MainWindow::onReplaceLast(QString text, QString suffix) { + qInfo() << "REPL TEXT" << text << "SUFFIX" << suffix; + QString editText = ui->updateStatus->toPlainText(); QStringList lines = editText.split('\n'); if (lines.size() > 0) { lines.removeLast(); - lines += text.leftJustified(m_width-10) + suffix; + if (!suffix.isNull() && suffix.size() > 0 && suffix != "\n") { + lines += text.leftJustified(m_width-10) + suffix; + } else { + lines += text.leftJustified(m_width-10); + } } for (int i=0; iupdateStatus->setText(lines.join('\n')); + ui->updateStatus->setText(lines.join('\n').trimmed()); ui->updateStatus->setEnabled(true); } - void MainWindow::onShowErrorMessage(QString title, QString text) { - QMessageBox::critical(this, title, text, QMessageBox::Ok); + text = text.leftJustified(50, ' '); + QMessageBox msgBox(QMessageBox::NoIcon, title, + text, QMessageBox::Ok, + nullptr, Qt::FramelessWindowHint); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setStyleSheet("QDialog {background-color: red;}" + "QPushButton {background-color: blue;}"); + QTimer *t = new QTimer(this); + connect(t, SIGNAL(timeout()), msgBox.defaultButton(), SLOT(click())); + t->setSingleShot(true); + t->start(5 * 1000); + + if(msgBox.exec() == QMessageBox::Ok) { + // do something + } else { + // do something else + } + disconnect(t, SIGNAL(timeout()), msgBox.defaultButton(), SLOT(click())); }