#!/usr/bin/env python
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
def print_qsize(sz, title=""):
print title, "W: ", sz.width(), " H: ", sz.height()
def __init__(self, parent=None):
self.setCentralWidget(centralwidget)
centralwidget.setLayout(layout)
checkbox1
= QCheckBox("Show First Widget", self
) checkbox2
= QCheckBox("Show Second Widget", self
) textedit1 = QPlainTextEdit(self)
textedit2 = QPlainTextEdit(self)
layout.addWidget(checkbox1)
layout.addWidget(textedit1)
layout.addWidget(checkbox2)
layout.addWidget(textedit2)
connect(checkbox1, SIGNAL("toggled(bool)"), lambda b: self.hide_resize(textedit1, b))
connect(checkbox2, SIGNAL("toggled(bool)"), lambda b: self.hide_resize(textedit2, b))
self.modify_widget(textedit1)
self.modify_widget(textedit2)
textedit1.hide()
textedit2.hide()
self.
layout().
setSizeConstraint(QLayout.
SetFixedSize)
def modify_widget(self, widget):
#this is needed so that the widget 'inherits' the existing size of the
#layout rather than forcing the layout to expand even further.. don't ask
#me how this works
def sizeHint():
widget.sizeHint = sizeHint
def hide_resize(self, widget, show=True):
if show:
#this doesn't work
widget.resize(widget.width(), 1)
widget.show()
#neither does this
widget.resize(widget.width(), 1)
#and neither do these:
a = QPropertyAnimation(widget, "height", widget)
a.setStartValue(1)
a.setEndValue(100)
a.setDuration(250)
a.start()
else:
widget.hide()
mw = ResizingWindow()
mw.show()
app.exec_()
#!/usr/bin/env python
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
connect = QObject.connect
app = QApplication(sys.argv)
def print_qsize(sz, title=""):
print title, "W: ", sz.width(), " H: ", sz.height()
class ResizingWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
centralwidget = QWidget(self)
self.setCentralWidget(centralwidget)
layout = QVBoxLayout()
centralwidget.setLayout(layout)
checkbox1 = QCheckBox("Show First Widget", self)
checkbox2 = QCheckBox("Show Second Widget", self)
textedit1 = QPlainTextEdit(self)
textedit2 = QPlainTextEdit(self)
layout.addWidget(checkbox1)
layout.addWidget(textedit1)
layout.addWidget(checkbox2)
layout.addWidget(textedit2)
connect(checkbox1, SIGNAL("toggled(bool)"), lambda b: self.hide_resize(textedit1, b))
connect(checkbox2, SIGNAL("toggled(bool)"), lambda b: self.hide_resize(textedit2, b))
self.modify_widget(textedit1)
self.modify_widget(textedit2)
textedit1.hide()
textedit2.hide()
self.layout().setSizeConstraint(QLayout.SetFixedSize)
def modify_widget(self, widget):
#this is needed so that the widget 'inherits' the existing size of the
#layout rather than forcing the layout to expand even further.. don't ask
#me how this works
def sizeHint():
return QSize(1, 1)
widget.sizeHint = sizeHint
def hide_resize(self, widget, show=True):
if show:
#this doesn't work
widget.resize(widget.width(), 1)
widget.show()
#neither does this
widget.resize(widget.width(), 1)
#and neither do these:
a = QPropertyAnimation(widget, "height", widget)
a.setStartValue(1)
a.setEndValue(100)
a.setDuration(250)
a.start()
else:
widget.hide()
mw = ResizingWindow()
mw.show()
app.exec_()
To copy to clipboard, switch view to plain text mode
Bookmarks