简体   繁体   English

使用多种颜色为macOS中的标题栏着色

[英]Colorizing the titlebar in macOS with multiple colors

I have a Qt app that runs on macOS. 我有一个可在macOS上运行的Qt应用程序。 I found a way to change the color of the titlebar here , however I want to take it a step further. 我在这里找到了一种更改标题栏颜色的方法,但是我想更进一步。 I want to mimic the titlebar that the Slack and Discord apps use. 我想模仿Slack和Discord应用程序使用的标题栏。 For example: 例如:

在此处输入图片说明

As you can see, the color of the controls in the window extend to the very top of the app's window. 如您所见,窗口中控件的颜色扩展到应用程序窗口的顶部。 I figure there are two ways to accomplish what I want: 我认为有两种方法可以实现我想要的功能:

  1. I can build on the code pasted above. 我可以在上面粘贴的代码上进行构建。 Looking through some of the Apple developer documentation, I think I can create a couple NsWindow s on top of the titlebar with whatever width I want and attach the titlebar as a parent for those windows. 查看一些Apple开发人员文档,我想我可以在标题栏上创建任意宽度的NsWindow ,并将标题栏作为这些窗口的父项附加。 Once I do that I should be able to make the same backgroundColor() color call for each one. 一旦这样做,我应该能够为每个调用相同的backgroundColor()颜色。 Of course, this will require me to keep track of when the controls or window are resized and adjust the NsWindow s of the titlebar, and I am not sure what (if any) issues that could cause. 当然,这将要求我跟踪控件或窗口的大小以及调整标题栏的NsWindow的时间,并且我不确定会导致什么(如果有)的问题。

  2. Maybe there is a way to essentially set the height of the titlebar to 0 ? 也许有一种方法可以将标题栏的高度设置为0 I wonder if that's what the Discord app is doing because: 我想知道这是否是Discord应用程序正在执行的操作,因为:

在此处输入图片说明

if you look closely, the edit box that says "Find or start a conversation" is vertically lined with the close, minimize and maximize buttons, as is the "Activity" label. 如果仔细观察,则显示“查找或开始对话”的编辑框与“关闭”,“最小化”和“最大化”按钮垂直对齐,“活动”标签也是如此。 But if the controls do extend to the top of the app's window then how are the standard app buttons getting painted? 但是,如果控件确实扩展到了应用程序窗口的顶部,那么如何绘制标准的应用程序按钮?

I'd be curious to know how Slack and Discord accomplish this even though I know they're not using Qt. 我很想知道Slack和Discord如何做到这一点,即使我知道他们没有使用Qt。

I realize there is not a Qt solution since Qt does not paint the titlebar. 我意识到没有Qt解决方案,因为Qt不会绘制标题栏。 I know this will be OS-specific, but since I do not have any real experience with Objective-C++ or working with Cocoa (all of my programming experience on macOS has been standard C++ with non-UI or Qt-based code) I'd appreciate any suggestions or guidance! 我知道这将是特定于OS的,但是由于我没有使用Objective-C ++或使用Cocoa的任何实际经验(我在macOS上的所有编程经验都是使用非UI或基于Qt的代码的标准C ++),因此我d感谢任何建议或指导!

Natively this is done with fullSizeContentView and titlebarAppearsTransparent properties of NSWindow . 在本地,这是通过NSWindow fullSizeContentViewtitlebarAppearsTransparent属性完成的。 Once you set them to true , you can draw or place controls beneath the title bar. 将它们设置为true ,可以在标题栏下方绘制或放置控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM