简体   繁体   中英

PyQt4: QPixMap signals?

Where can I find a list of the signals emitted by QPixMap, with descriptions? I looked in the official docs and I also googled "pyqt4 qpixmap signals" but I couldn't find anything.

I need this because I need to change the image displayed when the mouse hovers over the QPixMap. I was hoping to simply connect a function to a "hover" or "mouseover" signal, but I can't find such a thing.

A more general question: In the future, if I want to find a list of the signals emitted by a certain class, where can I find this information? Thanks.

You should handle the enter and leave events of the widget that displays the pixmaps. One way to do this is to install an event filter on the widget, like this:

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_())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM