本文介绍了PyQT 如何在 QPushbutton 上制作 QEvent.Enter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的主要目标是,我有一个 Qpushbutton 和一个框架,我想要做的是.当我将鼠标悬停在 Qpushbutton 上时,框架会显示出来.使用可见假.有人可以帮助我了解如何举办活动吗?
My main goal really is,i have a Qpushbutton and a frame, what im trying to do is. when i hover on a Qpushbutton the frame will show up. using visible false. can somebody help me please on how to make an events?
推荐答案
这是一个简单的例子,类似于我在你上一个问题中给出的例子:
Here's a quick example, similar to the example I gave in your previous question:
from PyQt4.QtGui import QApplication, QMainWindow, QPushButton, \
QWidget, QLabel
from PyQt4.QtCore import pyqtSignal
class HoverButton(QPushButton):
mouseHover = pyqtSignal(bool)
def __init__(self, parent=None):
QPushButton.__init__(self, parent)
self.setMouseTracking(True)
def enterEvent(self, event):
self.mouseHover.emit(True)
def leaveEvent(self, event):
self.mouseHover.emit(False)
class MainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.button = HoverButton(self)
self.button.setText('Button')
self.label = QLabel('QLabel uses QFrame...', self)
self.label.move(40, 40)
self.label.setVisible(False)
self.button.mouseHover.connect(self.label.setVisible)
def startmain():
app = QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.show()
sys.exit(app.exec_())
if __name__ == "__main__":
import sys
startmain()
这篇关于PyQT 如何在 QPushbutton 上制作 QEvent.Enter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!