QProgressBar, custom text position through stylesheet?
Unsolved
General and Desktop
-
I would like to position my QProgressBar text within the current chunk. I can compute the required offset myself, but it seems the label position can only be one of (left, center, right). Is there a way to position it with more granularity?
Bonus question: can we style the last chunk and give it a different color for instance?
Thanks a lot
-
Anyone has a clue?
-
Hi
I dont think its possible using stylesheets since it seems the text is using TextAligemnt and not an x,y pos.
I think you can do it using a QProxyStyle to override how it draws the text.It goes
case CE_ProgressBar: if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { QStyleOptionProgressBar subopt = *pb; subopt.rect = subElementRect(SE_ProgressBarGroove, pb, widget); proxy()->drawControl(CE_ProgressBarGroove, &subopt, p, widget); subopt.rect = subElementRect(SE_ProgressBarContents, pb, widget); proxy()->drawControl(CE_ProgressBarContents, &subopt, p, widget); if (pb->textVisible) { subopt.rect = subElementRect(SE_ProgressBarLabel, pb, widget); proxy()->drawControl(CE_ProgressBarLabel, &subopt, p, widget); } }
So its very likely you can overrride drawControl and for CE_ProgressBarLabel draw the text where you want.
-
Ok, thanks for the insight.