2014-01-18 49 views
1

我在哪裏可以找到QPixMap發出的信號列表,並附有說明?我查看了官方文檔,也搜索了「pyqt4 qpixmap signals」,但找不到任何東西。PyQt4:QPixMap信號?

我需要這個,因爲我需要更改鼠標懸停在QPixMap上時顯示的圖像。我只是希望將一個函數連接到「懸停」或「鼠標懸停」信號,但我找不到這樣的事情。

更常見的問題:未來,如果我想查找某個類別發出的信號列表,我可以在哪裏找到這些信息?謝謝。

回答

1

您應該處理顯示像素圖的小部件的enterleave事件。一種方法是在widget上安裝event filter,如下所示:

from PyQt4 import QtCore, QtGui 

class Window(QtGui.QWidget): 
    def __init__(self): 
     super(Window, self).__init__() 
     self.pixmap1 = QtGui.QPixmap('image1.jpg') 
     self.pixmap2 = QtGui.QPixmap('image2.jpg') 
     self.label = QtGui.QLabel(self) 
     self.label.setPixmap(self.pixmap1) 
     self.label.installEventFilter(self) 
     layout = QtGui.QVBoxLayout(self) 
     layout.addWidget(self.label) 

    def eventFilter(self, widget, event): 
     if widget is self.label: 
      if event.type() == QtCore.QEvent.Enter: 
       self.label.setPixmap(self.pixmap2) 
      elif event.type() == QtCore.QEvent.Leave: 
       self.label.setPixmap(self.pixmap1) 
     return super(Window, self).eventFilter(widget, event) 

if __name__ == '__main__': 

    import sys 
    app = QtGui.QApplication(sys.argv) 
    window = Window() 
    window.setGeometry(500, 300, 200, 200) 
    window.show() 
    sys.exit(app.exec_()) 
相關問題