当鼠标指向时会调用 def enterEvent(self, QEvent):但是我想在 def enterEvent(self, QEvent):里面修改用本身这个类创建的对象里面的值,我该怎么拿到上面那个类里的对象(而且上面那个类里的对象就是用我这个类来创建的对象)如果在这个类里用上面一个类另创一个对象当然就可以使用上面那个类的所以方法但是这样就递归深度了。谢谢帮帮我几天都没解决,是不是我哪里写错,
这个问题有救吗? 我需要在类里边更改对象的数值,但是这个对象又是用这个类创建的。
这个地方的window对象是用if __name__ == '__main__':的。当另一个界面切换到这个界面时python不走
if __name__ == '__main__':语句的所以这里的window对象不存在,直接崩掉了,
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QCursor, QIcon, QPixmap, QFont
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QMdiSubWindow, QLabel, QMainWindow, QGroupBox
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('Kapok') # APP名称
self.resize(620, 410) # 窗口大小
def button_python(self):
self.python = Button_python(self)
self.python.setWindowFlag(QtCore.Qt.FramelessWindowHint)
self.python.setMaximumSize(100, 137) # 限定最大尺寸
self.python.setMinimumSize(100, 100) # 限定最小尺寸
self.python.move(140, 33) # 按钮位置
self.python.setStyleSheet(
"Button_python{background:240,240,240;border-
radius:3px;}Button_python:hover{background:160,160,160;}")
self.label = QLabel(self.python)
self.label.setGeometry(3, 3, 94, 94)
self.label.setStyleSheet('QLabel{border:3px solid rgb(0,0,0);}')
ma_p = QPixmap('../Icon_file/python.jpg') # 标签加图片
self.label.setPixmap(ma_p) # 标签添加图片
self.label.setScaledContents(True)
class Button_python(QMdiSubWindow):
def __init__(self, parent=None):
super(Button_python, self).__init__(parent)
# other initializations...
def enterEvent(self, QEvent):
# here the code for mouse hover
print('鼠标停留')
#这个地方的window对象是用if __name__ == '__main__':的。当另一个界面切换到这个界面时python不走
#if __name__ == '__main__':语句的所以这里的window对象不存在,直接崩掉了,
window.python.move(140, 23)
window.python.resize(100, 137)
window.label.setGeometry(3, 3, 54, 54)
window.labels.show()
window.buupython.show()
def leaveEvent(self, QEvent):
# here the code for mouse leave
print('鼠标离开')
window.python.move(140, 33)
window.label.setGeometry(3, 3, 94, 94)
window.labels.hide()
window.buupython.hide()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())