当鼠标光标位于按钮上时,我需要处理事件。 例如,这种情况下我们应该使按钮的颜色变亮 当鼠标光标打开时。
我进行了很多搜索,但所有讨论都在
-> self.btn1.clicked.connect(self.function)
有没有办法使用btn1连接, -> self.btn1.mouse_Crusor_On.connect(self.fuction)??
如果不可能的话,我需要知道的是如何使用button.clicked 事件以'if'语法表示为CONDITION。
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5 import *
from PIL import Image
from PIL.ImageQt import ImageQt
import os
LocationX=list(range(50,1500,50))
LocationY=list(range(50,850,50))
class MainPage(QWidget):
def __init__(self, title="ATI: "):
super().__init__()
self.setWindowIcon(QtGui.QIcon('C:\\Users\\IAN\\Desktop\\GUI 연구\\images\\Icon.png'))
self.title = title
self.left = 250
self.top = 250
self.width = 1500
self.height = 850
self.widget()
self.setGeometry(30,50,1200,800)
def widget(self):
x=0
y=0
self.text="x:{0}, y:{1}".format(x,y)
self.label_mouseTest = QLabel(self.text, self)
self.label_mouseTest.setGeometry(0,0,300,40)
self.label_mouseTest.move(10,0)
self.setWindowTitle(self.title)
self.resize(self.width, self.height) # self.setGeometry(self.left, self.top, self.width, self.height)
self.move(self.left, self.top)
x1=LocationX[2]
y1=LocationY[5]
self.btn1 = QPushButton(self, text="임의폴더")
self.btn1.setToolTip("/Main/임의폴더")
self.btn1.move(x1-20,y1+30)
self.btn1.clicked.connect(self.open_folder)
# self.btn1.mouseCrusorOn.connect(self.change_loc)
# Folder Icon Part
self.label1 = QLabel(self, text="직빠구리")
self.label1.setGeometry(QRect(50, 5, 100, 50))
self.label1.move(x1,y1) #위치
pixmap=QPixmap("images/Folder.JPEG")
self.label1.setPixmap(pixmap)
self.label1.setFixedSize(30,30)
self.label1.setScaledContents(True)
self.show()
def mouseMoveEvent(self,e):
x=e.x()
y=e.y()
text2="x:{0}, y:{1}".format(x,y)
self.label_mouseTest.setText(text2)
X=int(x/50)
Y=int(y/50)
# if self.btn1.clicked():
# self.btn1.move(LocationX[X]-20,LocationY[Y]+30)
# self.label1.move(LocationX[X],LocationY[Y])