How to customize the title bar of a Qt app through Qt stylesheet?

六眼飞鱼酱① 提交于 2019-12-07 02:38:37

问题


I'm able to customize the controls of a Qt app in a Qt stylesheet. However, I couldn't find a way to customize the title bar. I found some solutions but that requires modifying the code of the app itself. Is there anyway you could customize it using just the Qt stylesheet?


回答1:


Title bar isn't a part of your application or Qt and it cannot be configured with stylesheet. Title bar is provided by Window manager. In some WMs there is no title bar at all. Most WMs support customisable themes for window decoration. Usualy you can configure you WM to display specific window with specific theme.

In Qt only QDockWidget's title bar can be configured by stylesheet.

P.S. Some applications disable decoration from window manager and draw title bar itself (example Chromium).




回答2:


Qt has no control over the appearance of the title bar and border of an application. This is the realm of the Window Manager (WM) in use. Qt can ask the WM to turn it off or only display certain buttons, but that's the extent of it.

The standard procedure for a customized title bar is to remove it, and then create and style your own take on the title bar in its place. To anyone watching, please note that this isn't as cool as you think it is. Some people like to customize their titlebar, most people like it when their application blends in with the rest of their operating environment (which it won't when you're done with it).

Short answer: there's no way to do this to an existing application using Qt stylesheets without changing the application's source code.



来源:https://stackoverflow.com/questions/4507864/how-to-customize-the-title-bar-of-a-qt-app-through-qt-stylesheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!