Example #1
0
ProgressUI::ProgressUI(QWidget *parent)
    : THWidgetBase(parent)
{
    timerId = -1;
    gradient = 0;
    hideTitleBar();
    setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool);
    setWindowModality(Qt::ApplicationModal);

    QVBoxLayout *v = new QVBoxLayout(this);
    v->setContentsMargins(5, 5, 5, 5);
    v->setSpacing(0);
    lbl = new QLabel(this);
    lbl->setStyleSheet(QStringLiteral("font-family:΢ÈíÑźÚ;font:12px;color:white;"));
    QProgressBar *pbar = new QProgressBar(this);
    pbar->setRange(0, 100);
    pbar->setValue(0);
    pbar->setFixedSize(260, 12);
    QFile file;
    file.setFileName(":res/css/progressbar.css");
    if (file.open(QIODevice::ReadOnly))
    {
        QByteArray ba = file.readAll();
        pbar->setStyleSheet(QTextCodec::codecForLocale()->toUnicode(ba));
    }
    file.close();
    v->addWidget(lbl, 1, Qt::AlignCenter);
    v->addWidget(pbar, 1, Qt::AlignCenter);
    setFixedSize(280, 50);

    connect(this, &ProgressUI::setValue, pbar, [=] (int value) {
        pbar->setValue(value);
        if (pbar->value() >= 100)
        {
            lbl->setText(QStringLiteral("Íê³É"));
            emit execFinished();
            QTimer::singleShot(1000, this, [=] () {
                disconnect(this, 0, 0, 0);
                this->close();
                this->deleteLater();
            });
        }
    });

    timerId = startTimer(60/*, Qt::VeryCoarseTimer*/);


}