pyqtSignal showWidget does not seem to work
-
Hi,
I am working on a project that was written with PyQt4 and I'm just trying to hide a couple of widgets and be invisible.
What I have:class MyApp(QtGui.QMainWindow, roverUI.Ui_MainWindow): showWidgetSignal = QtCore.pyqtSignal(object, object) self.showWidgetSignal.connect(self.showWidget) def warn_hide(self): self.showWidgetSignal.emit(self.WarnMsg, False) self.warn_hide()
but none of my widgets,
WarnMsg
norWarnTag
become invisible. I'mnot sure what could be wrong here, any hints?
This is while the below works fine (from the same file), i.e. the text get updated as expected:setTextSignal = QtCore.pyqtSignal(object, object) self.setTextSignal.connect(self.updateText) self.setTextSignal.emit(self.WarnMsg, "blablah")
This is an application running
ROS
.
Thank you!I missed to add the actual signal function
showWidget
, here it is:def showWidget(self, widget, bool): """Function to show and hide widgets. Args: widget (QWidget): The widget to be shown or hidden. bool (boolean): A boolean to specify if the widget needs to be shown or hidden. """ if bool: widget.show() else: widget.hide()
-
Is the event loop running (i.e. have you called
QApplication.exec_()
before callingself.warn_hide()
)? If not, you'll either need ro delay the call until the loop starts or callQApplication.processEvents()
.If that doesn't work (or make sense!) can you give a minimal example and the versions of Python and PyQt you are using please.
Hope this helps :o)
-
The signals must be declared at the same level of the methods:
class Foo(FooWidget): showWidgetSignal = QtCore.pyqtSignal(object, object) def __init__(self, parent=None): super(Foo, self).__init__(parent) self.showWidgetSignal.connect(self.showWidget) def warn_hide(self): self.showWidgetSignal.emit(self.WarnMsg, False) def bar(self): self.warn_hide()
-
The signals must be declared at the same level of the methods:
class Foo(FooWidget): showWidgetSignal = QtCore.pyqtSignal(object, object) def __init__(self, parent=None): super(Foo, self).__init__(parent) self.showWidgetSignal.connect(self.showWidget) def warn_hide(self): self.showWidgetSignal.emit(self.WarnMsg, False) def bar(self): self.warn_hide()
@eyllanesc said in pyqtSignal showWidget does not seem to work:
The signals must be declared at the same level of the methods:
class Foo(FooWidget): showWidgetSignal = QtCore.pyqtSignal(object, object) def __init__(self, parent=None): super(Foo, self).__init__(parent) self.showWidgetSignal.connect(self.showWidget) def warn_hide(self): self.showWidgetSignal.emit(self.WarnMsg, False) def bar(self): self.warn_hide()
They are all on the same level, however, the signal gets emitted from the context of a
Service()
(see here), I suspect that this is, what's causing the issue here. -
Is the event loop running (i.e. have you called
QApplication.exec_()
before callingself.warn_hide()
)? If not, you'll either need ro delay the call until the loop starts or callQApplication.processEvents()
.If that doesn't work (or make sense!) can you give a minimal example and the versions of Python and PyQt you are using please.
Hope this helps :o)
@jazzycamel said in pyqtSignal showWidget does not seem to work:
Is the event loop running (i.e. have you called
QApplication.exec_()
before callingself.warn_hide()
)? If not, you'll either need ro delay the call until the loop starts or callQApplication.processEvents()
.If that doesn't work (or make sense!) can you give a minimal example and the versions of Python and PyQt you are using please.
Hope this helps :o)
I'll give that a try, later even though, yes the loop should be running as interfacing with other Qt widgets works as expected.
Thanks and everything helps! :)