python - 当“鼠标在按钮上”时,我应该如何获得信号?(刚开,未按下)
问题描述
当鼠标光标位于按钮上时,我需要处理该事件。例如,当鼠标光标打开时,我们应该使按钮的颜色变亮。
我搜索了很多,但都在谈论
-->self.btn1.clicked.connect(self.function)
有什么方法可以使用 btn1 连接,例如 --> self.btn1.mouse_Crusor_On.connect(self.fction) ?
如果不可能,我需要知道的是如何使用 button.clicked 事件作为 'if' 语法中的条件。
- 下面有两组“#”,是有问题的部分。
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])
解决方案
推荐阅读
- python-3.x - 奇怪的#HASHTAG 编码
- c# - 使用 Azure Devops API 创建生成定义
- reactjs - 使用 react-dropzone 的文件上传进度
- javascript - 如何解决 GTM 中 JavaScript 编译器错误的 RegExp 问题?
- angular - 从 mat-sidenav-container 外部的按钮打开 mat-sidenav
- wordpress - wordpress custom plugin translation file not working
- java - 在 Recyclerview Android 中从 Firebase 中检索日期
- reactjs - How to handle API errors in a connected react component?
- php - Adding dynamic custom tab for WooCommerce products
- angular - 使用锚点单击显示 MatCalendar