Hi,
Anyone has tied this style in a Mac? The bar is always disabled and no text appears
Thanks
Printable View
Hi,
Anyone has tied this style in a Mac? The bar is always disabled and no text appears
Thanks
Does a plain QProgressBar work ok? Maybe an important setting was forgotten from the style option? See QProgressBar sources for reference how to fill it properly?
What style? QStyleOptionProgressBar is a little class that holds information about the parameters of an element that is to be drawn. If you want to use it, you have to fill this object with parameters.
Sorry the question was drawing a progress bar delegate in OSX, like the Qt Torrent example one (that fails too).
ATM I have solved it using a QPlastiqueStyle that's multiplatform.
Thank's
But does a plain QProgressBar get drawn ok? I mean the widget, not custom drawing.
an example of something you would use in the paint method of your delegate would be this:
Code:
QStyleOptionProgressBarV2 progressOptions; progressOptions.rect = option.rect; progressOptions.minimum = 0; progressOptions.maximum = 100; progressOptions.progress = 50; progressOptions.textVisible = true;
Where all of the values you would pull out of your model instead of hard coding them like i did in this example. The last line (setting textVisible to true) is what tells it to display text. If you don't set that to true it will only draw the physical progress bar without any text. I hope that helps you out.
The torrent example does set the text visible. This is how the example fills the style option:
It's interesting that the snippet above doesn't work in Mac. I would be really interested to hear whether an ordinary QProgressBar widget works as expected. QProgressBar fills the style option like this:Code:
// Set up a QStyleOptionProgressBar to precisely mimic the // environment of a progress bar. QStyleOptionProgressBar progressBarOption; progressBarOption.rect = option.rect; progressBarOption.minimum = 0; progressBarOption.maximum = 100; progressBarOption.textAlignment = Qt::AlignCenter; progressBarOption.textVisible = true; // Set the progress and text values of the style option. int progress = qobject_cast<MainWindow *>(parent())->clientForRow(index.row())->progress(); progressBarOption.progress = progress < 0 ? 0 : progress; // Draw the progress bar onto the view.
As you can see, the only remarkable difference is QStyleOption::initFrom() which initializes the state, direction, rect, palette, and fontMetrics. I can see from QStyleOption::initFrom() sources that some special tricks are done with state when Q_WS_MAC is in question. Maybe it's because of that?Code:
{ if (!option) return; option->initFrom(this); if (d->orientation == Qt::Horizontal) option->minimum = d->minimum; option->maximum = d->maximum; option->progress = d->value; option->textAlignment = d->alignment; option->textVisible = d->textVisible; option->text = text(); = qstyleoption_cast<QStyleOptionProgressBarV2 *>(option)) { optionV2->orientation = d->orientation; // ### Qt 5: use State_Horizontal instead optionV2->invertedAppearance = d->invertedAppearance; } }