[Qt-interest] Windows 7 style/theming (especially toolbars)
Joshua Grauman
jnfo-c at grauman.com
Mon Aug 23 00:40:30 CEST 2010
Thanks, this helps. Looking at the QWindowsVistaStyle code I can see it
definitely calls the Windows7 theme API (calls out to uxtheme.dll). Rather
than trying to call this myself, I'm thinking I should be able to use
QWindowsVistaStyle to paint the background of my QToolBar. I'm thinking I
would call QWindowsVistaStyle::drawControl() with the ControlElement set
to CE_MenuBarEmptyArea to draw onto a painter for my QToolBar. Does this
sound right? Would I need to subclass QToolBar in order to paint its
background or is there a better or easier way. Any tips would be
appreciated, styling/theming is new to me. Thanks!
Josh
> [reposting to qt-interest too..]
>
> Hi Josh
>
> I recommend looking at the source code for QWindowsVistaStyle and see how it
> draws the menu bar. It should be pretty easy to work out what it's doing.
> Take a look at the QStyle documentation to get a feel for how the rest of Qt
> invokes QStyle to render theme elements.
>
> You can probably hack something to create a gradient brush, either by copying
> it from QWindowsVistaStyle or hacking something together out of functions
> from the Windows7 theme API (which I've never looked at, by the way).
>
> As a last resort, in terms of accessing the gradient, if it's a linear
> gradient, you might be able to fudge it by reading back pixel colors from the
> window after the menu bar is drawn.
>
> Ross.
>
> ----- Original Message ----- From: "Josh" <jnfo-c at grauman.com>
> To: "Ross Bencina" <rossb-lists at audiomulch.com>
> Sent: Saturday, August 21, 2010 4:08 PM
> Subject: Re: [Qt-interest] Windows 7 style/theming (especially toolbars)
>
>
>> Ross,
>>
>> Thanks so much for the reply. I'd like my app to follow the active Windows7
>> theme, if that's easy. What I would 'like' to do, but don't know if it's
>> possible, is to get the brush that's used by the active Windows 7 theme to
>> paint the MenuBar, and then use that brush for the application-global style
>> sheet to set the background brush for QToolBar...
>>
>> Thanks!
>>
>> Josh
>>
>>> Josh wrote:
>>>> Does anyone know if Qt drawns the main menu (ie. File, Edit, etc.) at the
>>>> top of a main window or passes off the drawing to the OS? If Qt draws it,
>>>> maybe there is a way to get the background gradient it is using to draw
>>>> the main menu and use it for the background of toolbars? Any ideas?
>>>
>>> I think by default the toolbar background uses the QPallette.window()
>>> brush in the Windows style.
>>>
>>> If you create your own QStyle subclass (QWindowsStyle or
>>> QWindowsVistaStyle subclass perhaps?) you can definitely do whatever you
>>> like with regard to toolbar background rendering. You just need to hook in
>>> to the appropriate draw routines, and perhaps you need to also make the
>>> toolbars non-transparent, not sure, you can also do this in your QStyle
>>> subclass in the polish() method.
>>>
>>> An alternative might be to override the background brush for just QToolbar
>>> using an application-global style sheet.
>>>
>>> I guess the first question to ask is: do you just want it to look like
>>> Win7 or do you want it to follow the active Win7 theme?
>>>
>>> Good luck
>>>
>>> Ross.
>>>
>>>
>>>
>
More information about the Qt-interest-old
mailing list