const int currentVal = this->value();
const int max = this->maximum();
const int min = this->minimum();
opt.initFrom(this);
opt.minimum = min;
opt.maximum = max;
opt.progress = (currentVal >= 0) ? qAbs(max) : qAbs(min);
// Draw the groove. This should simply be the same size as the outside dimensions of the widget.
style
()->drawControl
(QStyle::CE_ProgressBarGroove,
&opt,
&painter,
this);
// Get the dimensions for the bar itself (within the groove). Depending on the active graphical
// style, this may be several pixels smaller that the dimensions of the widget, so that there's
// a narrow gutter inside the groove not occupied by the bar.
opt.
rect = style
()->subElementRect
(QStyle::SE_ProgressBarContents,
&opt,
this);
const float percentOfWidth = (float)(qAbs(currentVal)) / (float)(max - min);
const int left = opt.rect.topLeft().x();
const int right = opt.rect.topRight().x();
const int top = opt.rect.topLeft().y();
const int height = opt.rect.bottomLeft().y() - top + 1;
const int barWidth = (right - left) * percentOfWidth;
const int midPoint = left + ((right - left) / 2);
const int startPoint = (currentVal >= 0) ? midPoint : midPoint - barWidth;
opt.
rect = QRect(startPoint, top, barWidth
+ 2, height
);
style
()->drawControl
(QStyle::CE_ProgressBarContents,
&opt,
&painter,
this);
const int currentVal = this->value();
const int max = this->maximum();
const int min = this->minimum();
QStylePainter painter(this);
QStyleOptionProgressBar opt;
opt.initFrom(this);
opt.minimum = min;
opt.maximum = max;
opt.progress = (currentVal >= 0) ? qAbs(max) : qAbs(min);
// Draw the groove. This should simply be the same size as the outside dimensions of the widget.
style()->drawControl(QStyle::CE_ProgressBarGroove, &opt, &painter, this);
// Get the dimensions for the bar itself (within the groove). Depending on the active graphical
// style, this may be several pixels smaller that the dimensions of the widget, so that there's
// a narrow gutter inside the groove not occupied by the bar.
opt.rect = style()->subElementRect(QStyle::SE_ProgressBarContents, &opt, this);
const float percentOfWidth = (float)(qAbs(currentVal)) / (float)(max - min);
const int left = opt.rect.topLeft().x();
const int right = opt.rect.topRight().x();
const int top = opt.rect.topLeft().y();
const int height = opt.rect.bottomLeft().y() - top + 1;
const int barWidth = (right - left) * percentOfWidth;
const int midPoint = left + ((right - left) / 2);
const int startPoint = (currentVal >= 0) ? midPoint : midPoint - barWidth;
opt.rect = QRect(startPoint, top, barWidth + 2, height);
style()->drawControl(QStyle::CE_ProgressBarContents, &opt, &painter, this);
To copy to clipboard, switch view to plain text mode
Bookmarks