Search code examples
pythonpyqtpyqt4qsplitter

Removing a widget by invoking from a button which is set using QSplitter() in PyQt4


I want to make the "Application 1" disappear when the "Single" button is clicked. And show it again i mean both when "Split" button is clicked. Is there any method to make disappear/collapse a widget from QSplitter().

Here's the basic layout :

enter image description here

Thanks in advance.


Solution

  • QWidget has functions show() and hide(), if Application1 is inside QWidget or any other widget inheriting QWidget, you can call hide on the object of that widget when user clicks on Single button, (widget.hide()). When user clicks on Split button you can call show() on the same object to show the widget.

    Edit

    Another way of achieving this would be:

    to set the size of QSplitter. When Single Button is pressed, do the following:

    splitter.setSizes([self.width(), 0])
    

    When split button is pressed do the following:

    splitter.setSizes([self.width()/2, self.width()/2])
    

    Assuming that the self refer to mainWindow containing the splitter and self.width() gives the width of mainWindow.