-
Notifications
You must be signed in to change notification settings - Fork 0
/
QLinearGradientDemo.py
42 lines (31 loc) · 1.05 KB
/
QLinearGradientDemo.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
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
from PyQt5.QtGui import QPainter, QBrush, QPen, QLinearGradient
from PyQt5.QtCore import Qt
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.title = "PyQt5 Window"
self.top = 200
self.left = 500
self.width = 400
self.height = 300
self.InitWindow()
def InitWindow(self):
self.setWindowIcon(QtGui.QIcon("icon.png"))
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.show()
def paintEvent(self, e):
painter = QPainter(self)
painter.setPen(QPen(Qt.black, 0, Qt.SolidLine))
grad1 = QLinearGradient(0, 0, 200, 200)
grad1.setColorAt(0.0, Qt.darkGray)
grad1.setColorAt(0.5, Qt.green)
grad1.setColorAt(1.0, Qt.yellow)
painter.setBrush(QBrush(grad1))
painter.drawRect(10, 10, 200, 200)
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())