擅长:python、mysql、java
<p>你做错了的是,你用另一个布局对象提供QHLayout,而它只接受一个QWidget。</p>
<pre><code>Traceback (most recent call last):
File "C:/stackoverflow/QtVlayout.py", line 37, in <module>
myapp = Application()
File "C:/stackoverflow/QtVlayout.py", line 14, in __init__
self.createwidgets()
File "C:/stackoverflow/QtVlayout.py", line 23, in createwidgets
self.hLayout = QtGui.QHBoxLayout(self.mainLayout)
TypeError: arguments did not match any overloaded call:
QHBoxLayout(): too many arguments
QHBoxLayout(QWidget): argument 1 has unexpected type 'QVBoxLayout'
</code></pre>
<p>为了达到你的目的:</p>
<pre><code>self.mainLayout = QtGui.QVBoxLayout(self.mainWidget)
self.hLayout = QtGui.QHBoxLayout()
self.mainLayout.addLayout(self.hLayout)
</code></pre>
<p>并移除</p>
<pre><code>self.mainLayout.show()
</code></pre>
<p>这应该能解决问题。</p>