Skip to content

Instantly share code, notes, and snippets.

@gyu-don
Created April 17, 2016 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyu-don/d93e77e939e7b8255572ee2bdc69f87e to your computer and use it in GitHub Desktop.
Save gyu-don/d93e77e939e7b8255572ee2bdc69f87e to your computer and use it in GitHub Desktop.
PyQt4 stackoverflow
import sys
from PyQt4 import QtGui, QtCore
class Window(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
widget1 = QtGui.QDockWidget("Page 1")
widget1.setWidget(QtGui.QLabel("Page 1"))
widget2 = QtGui.QDockWidget("Page 2")
widget2.setWidget(QtGui.QLabel("Page 2"))
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, widget1)
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, widget2)
btn1 = QtGui.QPushButton("Page 1")
btn1.setCheckable(True)
btn1.setChecked(True)
btn1.toggled.connect(widget1.setShown)
widget1.visibilityChanged.connect(btn1.setChecked)
btn2 = QtGui.QPushButton("Page 2")
btn2.setCheckable(True)
btn2.setChecked(True)
btn2.toggled.connect(widget2.setShown)
widget2.visibilityChanged.connect(btn2.setChecked)
hlayout = QtGui.QHBoxLayout()
hlayout.addWidget(btn1)
hlayout.addWidget(btn2)
widget = QtGui.QWidget()
widget.setLayout(hlayout)
self.setCentralWidget(widget)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment