<font class="Apple-style-span" face="'courier new', monospace">This PyQt 4.6.2 program:</font><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">#--------------</font></div>
<div><div><font class="Apple-style-span" face="'courier new', monospace">from PyQt4.QtCore import *</font></div><div><font class="Apple-style-span" face="'courier new', monospace">from PyQt4.QtGui import *</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">class Btn(QPushButton):</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> def __init__(self, text):</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> super(Btn, self).__init__(text)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">app = QApplication([])</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">frm = QFrame()</font></div><div><font class="Apple-style-span" face="'courier new', monospace">frm.setMinimumSize(400, 300)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">lay = QVBoxLayout()</font></div><div><font class="Apple-style-span" face="'courier new', monospace">frm.setLayout(lay)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">lay.setAlignment(Qt.AlignRight)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">lay.addWidget(Btn("one"))</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">lay.addWidget(Btn("two two two two two"))</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">frm.show()</font></div><div><font class="Apple-style-span" face="'courier new', monospace">app.exec_()</font></div><div><div><font class="Apple-style-span" face="'courier new', monospace">#--------------</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">... produces a window like this:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">+----------------------------------------------------------+</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div><font class="Apple-style-span" face="'courier new', monospace"> +---------+</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> | one |</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div>
<font class="Apple-style-span" face="'courier new', monospace"> +---------+</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div>
<font class="Apple-style-span" face="'courier new', monospace"> +-------------------+</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> |two two two two two|</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div><font class="Apple-style-span" face="'courier new', monospace"> +-------------------+</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></span></font></div></span></font></div></span></font></div></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div>
<font class="Apple-style-span" face="'courier new', monospace">+----------------------------------------------------------+</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div></span></font></div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">But I *want* to produce a window like this:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">+----------------------------------------------------------+</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div><font class="Apple-style-span" face="'courier new', monospace"> +---------+</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> | one |</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div>
<font class="Apple-style-span" face="'courier new', monospace"> +---------+</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div>
<font class="Apple-style-span" face="'courier new', monospace"> +-------------------+</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> |two two two two two|</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div><font class="Apple-style-span" face="'courier new', monospace"> +-------------------+</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></span></font></div></span></font></div></span></font></div></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div>
<font class="Apple-style-span" face="'courier new', monospace">+----------------------------------------------------------+</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">Can I change this code to make this QVBoxLayout produce the desired result?</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">Note 1: This code change makes no difference in the window:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> lay.addWidget(Btn("one"), Qt.AlignRight)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-family: arial; "><div><font class="Apple-style-span" face="'courier new', monospace">Note 2: Using this QGridLayout *does* achieve the desired result:</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><div> lay = QGridLayout()</div><div> frm.setLayout(lay)</div>
<div> lay.addWidget(Btn("one"), 0, 0, Qt.AlignRight)</div><div> lay.addWidget(Btn("two two two two two"), 1, 0, Qt.AlignRight)</div><div><br></div></font></div></span></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">Tx,</font></div><div><font class="Apple-style-span" face="'courier new', monospace">John</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div></span></font></div></div><div></div></div></div>