forked from eee555/Metasweeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatusLabel.py
More file actions
40 lines (34 loc) · 1.69 KB
/
statusLabel.py
File metadata and controls
40 lines (34 loc) · 1.69 KB
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
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtGui import QPixmap
import configparser
class StatusLabel (QtWidgets.QLabel):
leftRelease = QtCore.pyqtSignal () # 定义信号
def __init__(self, parent=None):
super (StatusLabel, self).__init__ (parent)
config = configparser.ConfigParser()
config.read('gameSetting.ini')
self.pixSize = config.getint('DEFAULT','pixSize')
self.setFrameShape (QtWidgets.QFrame.Panel)
self.setFrameShadow (QtWidgets.QFrame.Raised)
self.setLineWidth(1)
self.setAlignment (QtCore.Qt.AlignCenter)
self.pixmap1 = QPixmap("media/f4.png")
self.pixmap1 = self.pixmap1.scaled(self.pixSize * 1.5, self.pixSize * 1.5)
self.pixmap2 = QPixmap("media/f0.png")
self.pixmap2 = self.pixmap2.scaled(self.pixSize * 1.5, self.pixSize * 1.5)
def mousePressEvent(self, e): ##重载一下鼠标点击事件
if e.button () == QtCore.Qt.LeftButton:
config = configparser.ConfigParser()
config.read('gameSetting.ini')
if self.pixSize == config.getint('DEFAULT','pixSize'):
self.setPixmap(self.pixmap1)
else:
self.pixmap1 = QPixmap("media/f4.png")
self.pixSize = config.getint('DEFAULT','pixSize')
self.pixmap1 = self.pixmap1.scaled(self.pixSize * 1.5, self.pixSize * 1.5)
self.setPixmap(self.pixmap1)
def mouseReleaseEvent(self, e):
if e.button () == QtCore.Qt.LeftButton:
self.setPixmap(self.pixmap2)
if self.pixSize * 1.5 >= e.localPos().x() >= 0 and 0 <= e.localPos().y() <= self.pixSize*1.5:
self.leftRelease.emit()