Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. pyqtSignal showWidget does not seem to work
Forum Update on Monday, May 27th 2025

pyqtSignal showWidget does not seem to work

Scheduled Pinned Locked Moved Solved Qt for Python
qt for python
5 Posts 4 Posters 819 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by cerr
    #1

    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()
    
    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      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)

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      cerrC 1 Reply Last reply
      1
      • eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by eyllanesc
        #3

        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()
        

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        cerrC 1 Reply Last reply
        1
        • eyllanescE eyllanesc

          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()
          
          cerrC Offline
          cerrC Offline
          cerr
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • jazzycamelJ jazzycamel

            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)

            cerrC Offline
            cerrC Offline
            cerr
            wrote on last edited by cerr
            #5

            @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! :)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved