SeriousAlexej / TabToolbar

A small library for creating tabbed toolbars
Other
284 stars 108 forks source link

Use the global application style for TTToolButtonStyle #15

Closed ojura closed 2 years ago

ojura commented 2 years ago

It looks like QProxyStyle uses the native OS style, even if we override it in the rest of the app by setting a global QApplication style.

This makes TTToolButtonStyle respect the global QApplication style.

ojura commented 2 years ago

Hey @SeriousAlexej, thanks for merging it so quickly :)

Unfortunately I afterwards realized there is a problem with this approach. Constructing a QProxyStyle from a QStyle* steals the ownership of the style object. In this case, from QApplication, so that’s not good.

Maybe we can have a single TTToolButtonStyle instance which would be used for all widgets in the ribbon, and then if the user is using a custom style, they can pass a new copy of their style to TabRibbon which TTToolButtonStyle can then take the ownership of, since unfortunately we can’t safely make a copy of qApp->style().

SeriousAlexej commented 2 years ago

Well that was unfortunate :D I dont have much free time till weekend so I guess it will be like that for a while. Cant evaluate the impact until then either, so if you think it might be better to revert PR for a while, please tell so.

ojura commented 2 years ago

Yes, for now I think it's best to revert.

It looks like QProxyStyle always steals the ownership of the passed QStyle*, while constructing it with nullptr will result in the native style being used.

So, it looks like the only proper solution is to enable the TabToolbar users to pass a copy of the same style they have set for qApp->style() which we can safely take the ownership of.

ojura commented 2 years ago

One other note - when you call QWidget::setStyle for the tool buttons, it doesn't take ownership, so you're actually leaking TTToolButtonStyle objects now! Ensuring there is only a single instance of TTToolButtonStyle would fix this.