alphanumeric
alphanumeric

Reputation: 19329

Controlling QProgressBar appearance

I would like to customize QProgressBar appearance by making it thin. There is a setMaximumHeight() method available. But unfortunately is cuts (or clips) the height of the Progress Bar by making it look weird. Instead I would rather squeeze or scale it vertically. The problem of clipping is especially evident on OSX platform. Here is the illustration:

enter image description here

Upvotes: 1

Views: 1510

Answers (1)

This cannot be easily done if the styling is done by the platform that Qt runs on. On both Windows and OS X, the styling of widgets is actually rendered by the platform APIs. The size of the primitives is set by the styling selected by the user (to the extent that it's user-selectable, of course).

A trivial workaround is to override the platform style. You can do it by setting a non-empty stylesheet on the widget. Since the stylesheets only have meaning to Qt and the platform style APIs wouldn't know what to do with them, a non-empty stylesheet completely disables platform styling for the given widget. You start up with a very sparse, Qt-provided style. This relaxes the fixed platform-specific dimensions. You'll of course have to provide a stylesheet that is platform specific to approximate the native look of the control - only that now you can size the control to your liking.

Your workaround of scaling the control's image is of course possible. You need to render() the widget onto a pixmap or an image, then scale it, and use it to render your target widget. You'd need to write a wrapper widget for that. The wrapper needs to make itself "appear" to act exactly as the wrapped widget would, except for the size limitations. This will require forwarding of events, sizes and size limits (with desired alterations), management of painting, etc.

Upvotes: 3

Related Questions