forked from harry159821/XiamiForLinuxProject
-
Notifications
You must be signed in to change notification settings - Fork 2
/
titleBar.py
105 lines (88 loc) · 3.94 KB
/
titleBar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python
# -*- coding:utf-8 -*-
from PyQt4 import QtGui,QtCore,Qt
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.Qt import *
class titleBar(QtGui.QWidget):
def __init__(self,parent=None):
super(titleBar,self).__init__(parent)
self.title_label = QLabel()
self.title_label.setStyleSheet("color:black")
self.title_label.setText(u"虾米音乐")
self.font = QtGui.QFont()
self.font.setPixelSize(20) #设置字号32,以像素为单位
self.font.setFamily("SimSun")#设置字体,宋体
self.font.setFamily(u"微软雅黑")
#self.font.setWeight(20) #设置字型,不加粗
self.font.setBold(True)
self.font.setItalic(False) #设置字型,不倾斜
self.font.setUnderline(False)#设置字型,无下划线
self.title_label.setFont(self.font)
self.close_button = QLabel()
self.min_button = QLabel()
self.max_button = QLabel()
self.close_button.setPixmap(QPixmap("./img/orange.png"))
self.min_button.setPixmap(QPixmap("./img/green.png"))
self.max_button.setPixmap(QPixmap("./img/blue.png"))
self.close_button.setFixedSize(15,15)
self.min_button.setFixedSize(15,15)
self.max_button.setFixedSize(15,15)
self.close_button.setStyleSheet("""
background:transparent
""")
self.min_button.setStyleSheet("""
background:transparent
""")
self.max_button.setStyleSheet("""
background:transparent
""")
self.title_label.setStyleSheet("""
background:transparent;
color:rgba(70,70,70,255);
""")
self.close_button.setScaledContents(True)
self.min_button.setScaledContents(True)
self.max_button.setScaledContents(True)
self.searchLine = QtGui.QLineEdit()
self.searchLine.setStyleSheet("""
border:2px groove gray;
border-radius:10px;
text-align:center;
padding:2px 10px;
background:white;
""")
self.setStyleSheet('''
border-bottom: 0px solid rgb(170, 170, 170);
background: qlineargradient(spread:reflect,
x1:1, y1:1, x2:1, y1:1,
stop:1 rgba(250, 250, 250, 255),
stop:0 rgba(170, 170, 170, 255));
''')
#水平管理器
self.title_layout = QHBoxLayout()
self.title_layout.addWidget(self.close_button,0,Qt.AlignVCenter)
self.title_layout.addWidget(self.min_button ,0,Qt.AlignVCenter)
self.title_layout.addWidget(self.max_button ,0,Qt.AlignVCenter)
self.title_layout.addStretch()
self.title_layout.addWidget(self.title_label,1,Qt.AlignCenter)
self.title_layout.addWidget(self.searchLine)
self.setLayout(self.title_layout)
self.resize(1000, 60)
self.setMaximumSize(1000, 60)
self.setMinimumSize(1000, 60)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
QApplication.postEvent(self, QEvent(174))
event.accept()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton:
self.move(event.globalPos() - self.dragPosition)
event.accept()
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
TitleBar = titleBar()
TitleBar.show()
sys.exit(app.exec_())