What is the way of getting the Sender of a right-mouse-click on a QLabel()? I want to know on which Widget the right-mouse-click happened. I have code to get the position, but how can i get the Sender?
Getting the Sender i could retrieve the accessibleName()
Here is my current minimal Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import * #!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
# qbtn = QtGui.QPushButton('Quit', self)
label = QLabel("BG Sessions", self)
label.setContextMenuPolicy(Qt.CustomContextMenu)
label.setObjectName("title")
label.customContextMenuRequested.connect(self.clearCache)
label.move(50, 50)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Quit button')
self.show()
def clearCache(self, pos):
print pos
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()