How to detect any mouse click on PySide Gui?

pyqt, pyside, python, qt, user-interface

Solution

Define `mousePressEvent` inside `Main`:

from PySide.QtCore import *
from PySide.QtGui import *

import sys


class Main(QWidget):


    def __init__(self, parent=None):
        super(Main, self).__init__(parent)

        layout  = QHBoxLayout(self)
        layout.addWidget(QLabel("this is the main frame"))

    def mousePressEvent(self, QMouseEvent):
        #print mouse position
        print QMouseEvent.pos()


a = QApplication([])
m = Main()
m.show()
sys.exit(a.exec_())

Problem

I am trying implement a feature such that when a mouse is clicked on the gui, a function is triggered Below is my mouse click detection, it doesn't work when I click on any part of the gui ``` from PySide.QtCore import * from PySide.QtGui import * import sys class Main(QWidget): def __init__(self, parent=None): super(Main, self).__init__(parent) layout = QHBoxLayout(self) layout.addWidget(QLabel("this is the main frame")) layout.gui_clicked.connect(self.anotherSlot) def anotherSlot(self, passed): print passed print "now I'm in Main.anotherSlot" class MyLayout(QHBoxLayout): gui_clicked = Signal(str) def __init__(self, parent=None): super(MyLayout, self).__init__(parent) def mousePressEvent(self, event): print "Mouse Clicked" self.gui_clicked.emit("emit the signal") a = QApplication([]) m = Main() m.show() sys.exit(a.exec_()) ``` This is my goal ``` Mouseclick.gui_clicked.connect(do_something) ``` Any advice would be appreciated

Original source