From 4307fb96a605b5c3b68634efd030b57f0d75ca3b Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 22 Aug 2023 09:27:59 +0200 Subject: [PATCH] Add status bar instead of using an message box for displaying error messages. --- mainwindow.cpp | 38 ++++++++++++-------------------------- mainwindow.h | 1 + 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index a587a62..9151fc1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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); } diff --git a/mainwindow.h b/mainwindow.h index 5dcef5b..e54b0fc 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,6 +3,7 @@ #include #include +#include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; }