#qt creator progress bar

6 messages · Page 1 of 1 (latest)

wraith charm
#

im tryna change the color of my progress bar when it goes within a certain range, it works with css code but i need everything to be in c++, right now it works but the color is green throughout

lunar flowerBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

#

@wraith charm

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
wraith charm
#

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);

}

MainWindow::~MainWindow()
{
delete ui;
}
// Implementation of the new function
void MainWindow::updateProgressBarColor()
{

int value = ui->progressBar->value();
qDebug() << "Progress Bar Value:" << value;


// Define ranges and corresponding colors
QColor color;
if (value >= 0 && value < 30) {
    color = QColor(Qt::red);
} else if (value >= 30 && value < 70) {
    color = QColor(Qt::yellow);
} else {
    color = QColor(Qt::green);
}

QPalette palette = ui->progressBar->palette();
palette.setColor(QPalette::Highlight, color);
ui->progressBar->setPalette(palette);

}

void MainWindow::on_submitButton_clicked()
{

int currentValue = ui->progressBar->value();
if (currentValue < ui->progressBar->maximum()) {
    int newValue = currentValue + 10; // You can adjust the increment value as per your requirement
    if (newValue <= ui->progressBar->maximum()) {
        ui->progressBar->setValue(newValue);
    } else {
        ui->progressBar->setValue(ui->progressBar->maximum());
    }
     updateProgressBarColor();
}

}

void MainWindow::on_clearButton_clicked()
{
int currentValue = ui->progressBar->value();
if (currentValue > ui->progressBar->minimum()) {
int newValue = currentValue - 10; // Decrement value by 10
if (newValue >= ui->progressBar->minimum()) {
ui->progressBar->setValue(newValue);
} else {
ui->progressBar->setValue(ui->progressBar->minimum());
}
updateProgressBarColor();
}
}

#

even when i try to set the color generally it doesnt work without any conditonns , could some one please help