Add status bar instead of using an message box for displaying error messages.

This commit is contained in:
Gerhard Hoffmann 2023-08-22 09:27:59 +02:00
parent c35390b6d6
commit 4307fb96a6
2 changed files with 13 additions and 26 deletions

View File

@ -16,6 +16,16 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
, m_width(70)
, m_progressRunning(false)
, m_progressValue(0) {
this->setStatusBar(new QStatusBar(this));
QFont f;
f.setStyleHint(QFont::Monospace);
f.setWeight(QFont::Bold);
f.setFamily("Misc Fixed");
f.setPixelSize(12);
this->statusBar()->setFont(f);
ui->setupUi(this);
ui->updateProgress->setRange(0, 100);
@ -214,30 +224,6 @@ void MainWindow::onReplaceLast(QString text, QString suffix) {
}
void MainWindow::onShowErrorMessage(QString title, QString text) {
text = text.leftJustified(50, ' ');
QMessageBox msgBox(QMessageBox::NoIcon, title,
text, QMessageBox::Ok,
this, Qt::FramelessWindowHint);
msgBox.resize(100, 50);
// msg.setStyleSheet("background-color: rgb(0, 0, 0);")
// msg.setStyleSheet("text-color: rgb(255, 255, 255);")
msgBox.setStyleSheet("QMessageBox{border: 1px solid black; background-color:white}");
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.defaultButton()->setVisible(false);
QTimer *t = new QTimer(this);
connect(t, SIGNAL(timeout()), msgBox.defaultButton(), SLOT(click()));
t->setSingleShot(true);
t->start(5 * 1000);
msgBox.show();
msgBox.move(0, 0);
if(msgBox.exec() == QMessageBox::Ok) {
// do something
} else {
// do something else
}
this->statusBar()->showMessage( // timeout: 5000
QString(title + ": " + text).leftJustified(80, ' '), 20000);
}

View File

@ -3,6 +3,7 @@
#include <QMainWindow>
#include <QTimer>
#include <QStatusBar>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }