2011-08-03 27 views

回答

3

這裏有一個簡單的例子,類似於我在你前面的問題給的例子:

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() 
+0

您好感謝您的例子。這只是想我需要再次學習感謝 – Katherina