likage
2018-12-06 19:59:27 UTC
Hi all,
I am trying to create a 'clicked' signal where it will only be triggered if
User clicks anywhere within the icon.
In the following code:
class TestWin(QtGui.QWidget):
def __init__(self, parent=None):
super(TestWin, self).__init__(parent)
self.init_ui()
def init_ui(self):
lyt = QtGui.QVBoxLayout()
btn = QtGui.QPushButton('test button')
lbl = QtGui.QLabel()
icon_path = '/Desktop/people.png'
lbl.setPixmap(icon_path)
lyt.addWidget(btn)
lyt.addWidget(lbl)
self.setLayout(lyt)
# Signals
btn.clicked.connect(self.btn_click)
lbl.mousePressEvent = self.lbl_click
def btn_click(self):
print 'I am clicking on the button...'
def lbl_click(self, event):
print 'I am clicking on the label...'
my_win = TestWin()
my_win.show()
As soon as I resize the window bigger, clicking on any blank space will
still prints the message 'I am clicking on the label'
I also tried using event filtering where as follows:
class TestWin(QtGui.QWidget):
def __init__(self, parent=None):
super(TestWin, self).__init__(parent)
self.init_ui()
def init_ui(self):
...
...
# Signals
btn.clicked.connect(self.btn_click)
lbl.installEventFilter(self)
def btn_click(self):
...
def eventFilter(self, source, event):
if event.type() == QtCore.QEvent.MouseButtonPress:
print "The sender is:", source.text() # Returns me blank
return super(TestWin, self).eventFilter(source, event)
but the `source.text()` is returning me nothing.
Any insights are appreciated!
I am trying to create a 'clicked' signal where it will only be triggered if
User clicks anywhere within the icon.
In the following code:
class TestWin(QtGui.QWidget):
def __init__(self, parent=None):
super(TestWin, self).__init__(parent)
self.init_ui()
def init_ui(self):
lyt = QtGui.QVBoxLayout()
btn = QtGui.QPushButton('test button')
lbl = QtGui.QLabel()
icon_path = '/Desktop/people.png'
lbl.setPixmap(icon_path)
lyt.addWidget(btn)
lyt.addWidget(lbl)
self.setLayout(lyt)
# Signals
btn.clicked.connect(self.btn_click)
lbl.mousePressEvent = self.lbl_click
def btn_click(self):
print 'I am clicking on the button...'
def lbl_click(self, event):
print 'I am clicking on the label...'
my_win = TestWin()
my_win.show()
As soon as I resize the window bigger, clicking on any blank space will
still prints the message 'I am clicking on the label'
I also tried using event filtering where as follows:
class TestWin(QtGui.QWidget):
def __init__(self, parent=None):
super(TestWin, self).__init__(parent)
self.init_ui()
def init_ui(self):
...
...
# Signals
btn.clicked.connect(self.btn_click)
lbl.installEventFilter(self)
def btn_click(self):
...
def eventFilter(self, source, event):
if event.type() == QtCore.QEvent.MouseButtonPress:
print "The sender is:", source.text() # Returns me blank
return super(TestWin, self).eventFilter(source, event)
but the `source.text()` is returning me nothing.
Any insights are appreciated!
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4913a8b5-eb22-4ffd-a3d2-268dc029ab8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4913a8b5-eb22-4ffd-a3d2-268dc029ab8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.