简体   繁体   English

如何使用PyQt4创建自定义窗口标题栏?

[英]How do I create a custom window title bar using PyQt4?

I am finding a way to customize my window title bar for my PyQt4 application. 我正在寻找一种为PyQt4应用程序自定义窗口标题栏的方法。 As far as I understand, It is not possible to use Style-sheet for this purpose. 据我了解,无法将Style-sheet用于此目的。 Instead I have to hide the title bar with 相反,我必须隐藏标题栏

.setWindowFlags(QtCore.Qt.FramelessWindowHint) 

and implement my own title bar. 并实现我自己的标题栏。 This is where I am puzzled as I have seen someone did use a QHboxlayout with QLabel (for window title name) and QButton (for exit,max,min actions) to make one like this 这是我感到困惑的地方,因为我看到有人确实使用了带有QLabel (用于窗口标题名称)和QButton (用于退出,最大,最小动作)的QHboxlayout来制作这样的图片

在此处输入图片说明

And he used Style-Sheets to decorate each individual widgets. 并且他使用Style-Sheets来装饰每个单独的小部件。 That's probably fine for a simple title bar. 对于一个简单的标题栏可能就很好了。 But what if I want more complicated title bar like this? 但是,如果我想要更复杂的标题栏怎么办?

在此处输入图片说明

I don't think just by altering Style-Sheets properties will give me this kind of looks. 我不认为仅通过更改Style-Sheets属性即可获得这种外观。

So,my question is, is it possible to create such a complicated title bar in PyQt4 ? 所以,我的问题是,是否有可能在PyQt4创建如此复杂的标题栏? If so, as a beginner, what should I be looking at? 如果是这样,作为初学者,我应该看什么? I will dig and learn the concept by myself, I just needs some directions. 我将自己挖掘和学习概念,我只需要一些指导。

Perhaps I am too late in replying, but anyway, I'll just let you know a few thing I have pickup myself. 也许我回答太晚了,但是无论如何,我只会让您知道我已经接管自己的一些事情。 For one, it is quite easy to create such a "complicated" title bar, and UI using PyQt4. 首先,使用PyQt4创建这样的“复杂”标题栏和UI非常容易。 I would recommend you to read this post 我建议您阅读这篇文章

Stacking QPushButtons on the other side of a QMenuBar 将QPushButtons堆叠在QMenuBar的另一侧

The UI for the max/min/close buttons may be achieved using style sheets - you'll have to tinker with it a fair amount. 可以使用样式表来实现最大/最小/关闭按钮的用户界面-您必须对其进行大量修改。 If you have trouble adapting the code from Qt4 to PyQt4 you can mail me, I'll do my best to help you. 如果您在将代码从Qt4更改为PyQt4时遇到问题,可以给我发邮件,我会尽力为您提供帮助。

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

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