1 from PyQt4
import QtGui
2 from PyQt4
import QtCore
4 def create_button(text
, layout
=None):
5 """Create a button, set its title, and add it to the parent."""
6 button
= QtGui
.QPushButton()
9 layout
.addWidget(button
)
13 class QFlowLayoutWidget(QtGui
.QWidget
):
15 _horizontal
= QtGui
.QBoxLayout
.LeftToRight
16 _vertical
= QtGui
.QBoxLayout
.TopToBottom
18 def __init__(self
, parent
=None):
19 QtGui
.QWidget
.__init
__(self
, parent
)
20 self
._direction
= self
._vertical
21 layout
= QtGui
.QBoxLayout(self
._direction
)
24 self
.setLayout(layout
)
25 self
.setContentsMargins(2, 2, 2, 2)
26 policy
= QtGui
.QSizePolicy(QtGui
.QSizePolicy
.Minimum
,
27 QtGui
.QSizePolicy
.Minimum
)
28 self
.setSizePolicy(policy
)
29 self
.setMinimumSize(QtCore
.QSize(1, 1))
31 def resizeEvent(self
, event
):
33 if size
.width() * 0.8 < size
.height():
36 dxn
= self
._horizontal
38 if dxn
!= self
._direction
:
40 self
.layout().setDirection(dxn
)