-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscrollLabel.py
63 lines (53 loc) · 1.86 KB
/
scrollLabel.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
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 6 12:39:16 2023
@author: amrdo
"""
from PyQt5.QtWidgets import QMainWindow, QApplication,QLabel
from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5 import uic
from PyQt5.QtCore import Qt
import interface
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtWidgets
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas
import matplotlib
import functions
class ScrollLabel(QLabel):
dragged= pyqtSignal(int,int)
def __init__(self,parent=None):
super(ScrollLabel, self).__init__(parent)
self.prev_pos = None
self.xloc=0
self.yloc=0
def mousePressEvent(self, event):
self.prev_pos = event.pos()
def mouseMoveEvent(self, event):
global xloc
global yloc
if self.prev_pos:
# Calculate the difference between current and previous positions
delta = event.pos() - self.prev_pos
# Detect the direction of mouse movement
if delta.x() > 0:
#print("Mouse dragged to the right")
self.xloc+=1
#print(self.xloc)
elif delta.x() < 0:
#("Mouse dragged to the left")
self.xloc-=1
#print(self.xloc)
if delta.y() > 0:
#print("Mouse dragged down")
self.yloc-=1
#print(self.yloc)
elif delta.y() < 0:
#print("Mouse dragged up")
self.yloc+=1
#print(self.yloc)
# Update the previous position for the next event
self.prev_pos = event.pos()
self.dragged.emit(self.xloc,self.yloc)
def mouseReleaseEvent(self, event):
self.prev_pos = None