Don't hide "OK" on message timer, just disable it
This commit is contained in:
parent
d1fb7fde16
commit
dcff063f19
@ -1,7 +1,10 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "debug_functions.h"
|
#include "debug_functions.h"
|
||||||
@ -22,16 +25,38 @@ void call_error(QString p_message)
|
|||||||
|
|
||||||
void call_notice(QString p_message)
|
void call_notice(QString p_message)
|
||||||
{
|
{
|
||||||
QMessageBox *msgBox = new QMessageBox;
|
auto *msgBox = new QMessageBox;
|
||||||
|
|
||||||
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
msgBox->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
msgBox->setText(p_message);
|
msgBox->setText(p_message);
|
||||||
msgBox->setWindowTitle(
|
msgBox->setWindowTitle(
|
||||||
QCoreApplication::translate("debug_functions", "Notice"));
|
QCoreApplication::translate("debug_functions", "Notice"));
|
||||||
|
|
||||||
msgBox->setStandardButtons(QMessageBox::NoButton);
|
msgBox->setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox->setDefaultButton(QMessageBox::Ok);
|
||||||
|
msgBox->defaultButton()->setEnabled(false);
|
||||||
|
|
||||||
QTimer::singleShot(3000, msgBox, std::bind(&QMessageBox::setStandardButtons,msgBox,QMessageBox::Ok));
|
QTimer intervalTimer;
|
||||||
|
intervalTimer.setInterval(1000);
|
||||||
|
|
||||||
|
int counter = 3;
|
||||||
|
const auto updateCounter = [msgBox, &counter] {
|
||||||
|
if (counter <= 0)
|
||||||
|
return;
|
||||||
|
msgBox->defaultButton()->setText(
|
||||||
|
QString("%1 (%2)").arg(QDialogButtonBox::tr("OK")).arg(counter));
|
||||||
|
counter--;
|
||||||
|
};
|
||||||
|
|
||||||
|
QObject::connect(&intervalTimer, &QTimer::timeout, msgBox, updateCounter);
|
||||||
|
intervalTimer.start();
|
||||||
|
updateCounter();
|
||||||
|
|
||||||
|
QTimer::singleShot(3000, msgBox, [msgBox, &intervalTimer] {
|
||||||
|
msgBox->defaultButton()->setEnabled(true);
|
||||||
|
msgBox->defaultButton()->setText(QDialogButtonBox::tr("OK"));
|
||||||
|
intervalTimer.stop();
|
||||||
|
});
|
||||||
|
|
||||||
msgBox->exec();
|
msgBox->exec();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user