Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 nor WarnTag 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 calling self.warn_hide())? If not, you'll either need ro delay the call until the loop starts or call QApplication.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()
    


  • @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.



  • @jazzycamel said in pyqtSignal showWidget does not seem to work:

    Is the event loop running (i.e. have you called QApplication.exec_() before calling self.warn_hide())? If not, you'll either need ro delay the call until the loop starts or call QApplication.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! :)


  • Banned

    Note I see several issues by just looking at your snippet of code which by no means fully addresses the issue you may be having since you are not providing an MRE (Minimal Reproducible Example) that can be copy/pasted and ran to see your issue and then help you troubleshoot what you did wrong. Provide a MRE and I will almost guarantee either I or someone else will figure out what you are doing wrong. Or another way to put it might be if you give us Snippets of an MRE expect to get either no answer or a snippet of an answer which will most likely not solve your problem


Log in to reply