Not sure I see how setFormat() can be used to get a percentage value that is not integer. The placeholder "%p" gets an integer as a string. You could get a string like "9 of 37" from "%v of %m" but you cannot compute with these placeholders.
You could subclass QProgressBar and override QProgressBar::text():
#ifndef FRACTIONALPROGRESSBAR_H
#define FRACTIONALPROGRESSBAR_H
#include <QProgressBar>
{
public:
FractionalProgressBar
(QWidget *p
= nullptr
);
// QProgressBar interface
public:
virtual QString text
() const Q_DECL_OVERRIDE;
};
#endif // FRACTIONALPROGRESSBAR_H
#ifndef FRACTIONALPROGRESSBAR_H
#define FRACTIONALPROGRESSBAR_H
#include <QProgressBar>
class FractionalProgressBar : public QProgressBar
{
public:
FractionalProgressBar(QWidget *p = nullptr);
// QProgressBar interface
public:
virtual QString text() const Q_DECL_OVERRIDE;
};
#endif // FRACTIONALPROGRESSBAR_H
To copy to clipboard, switch view to plain text mode
#include "fractionalprogressbar.h"
FractionalProgressBar
::FractionalProgressBar(QWidget *p
):{
}
QString FractionalProgressBar
::text() const {
if ( minimum() == maximum() ) // divide by zero guard
double percent = 100.0 * (value() - minimum()) / (maximum() - minimum());
return QString("%1%").
arg(percent,
0,
'f',
1);
}
#include "fractionalprogressbar.h"
FractionalProgressBar::FractionalProgressBar(QWidget *p):
QProgressBar(p)
{
}
QString FractionalProgressBar::text() const
{
if ( minimum() == maximum() ) // divide by zero guard
return QString();
double percent = 100.0 * (value() - minimum()) / (maximum() - minimum());
return QString("%1%").arg(percent, 0, 'f', 1);
}
To copy to clipboard, switch view to plain text mode
Bookmarks