QHBoxLayout(QWidget):参数1有意想不到的类型“QVBoxLayout”

时间:2022-07-25 23:05:01

I'm creating a layout for a GUI that is supposed to have a QVBoxLayout for main layout and QHBoxLayout for sublayout, but for some reason it gives me this error.

我正在为一个GUI创建一个布局,它应该有一个QVBoxLayout用于主布局和QHBoxLayout,但是出于某种原因,它给了我这个错误。

Here is the code:

这是代码:

class Application(QtGui.QMainWindow):

        err1 = QtCore.pyqtSignal(int)
        reset = QtCore.pyqtSignal()

        def __init__(self, parent=None):
          super(Application, self).__init__()
          self.setGeometry(300, 300, 600, 600)
          self.setWindowTitle('IPv6 traffic generator')
          PlotWidget(self)
          self.createwidgets()

        def createwidgets(self):


          self.mainWidget = QtGui.QWidget(self) 
          self.setCentralWidget(self.mainWidget)

          self.mainLayout = QtGui.QVBoxLayout(self.mainWidget)
          self.hLayout = QtGui.QHBoxLayout(self.mainLayout)

             ---- creating widgets ----

          self.hLayout.addWidget(self.label2)
          self.hLayout.addWidget(self.menubutton1)
          self.hLayout.addWidget(self.label3)
          self.hLayout.addWidget(self.button2)
          self.hLayout.addWidget(self.button3)
          self.mainLayout.setLayout(self.hLayout)
          self.mainLayout.show()

2 个解决方案

#1


3  

What you have done wrong is that , your providing QHLayout with another Layout object while it accepts only a QWidget.

您所做的错误的是,您的QHLayout与另一个布局对象,而它只接受一个QWidget。

Traceback (most recent call last):
File "C:/*/QtVlayout.py", line 37, in <module>
    myapp = Application()
  File "C:/*/QtVlayout.py", line 14, in __init__
    self.createwidgets()
  File "C:/*/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'

So to achieve what your trying to do :

为了达到你的目的

self.mainLayout = QtGui.QVBoxLayout(self.mainWidget)
self.hLayout = QtGui.QHBoxLayout()
self.mainLayout.addLayout(self.hLayout)

and remove

和删除

self.mainLayout.show()

This should solve the issue .

这应该能解决这个问题。

#2


0  

The proto type of construct a QLayout is

构建QLayout的proto类型是。

def __init__(self, QWidget=None): # real signature unknown; restored from __doc__ with multiple overloads
    pass

so, you need to construct like this:

所以,你需要这样构造:

self.hLayout = QtGui.QHBoxLayout(self)

#1


3  

What you have done wrong is that , your providing QHLayout with another Layout object while it accepts only a QWidget.

您所做的错误的是,您的QHLayout与另一个布局对象,而它只接受一个QWidget。

Traceback (most recent call last):
File "C:/*/QtVlayout.py", line 37, in <module>
    myapp = Application()
  File "C:/*/QtVlayout.py", line 14, in __init__
    self.createwidgets()
  File "C:/*/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'

So to achieve what your trying to do :

为了达到你的目的

self.mainLayout = QtGui.QVBoxLayout(self.mainWidget)
self.hLayout = QtGui.QHBoxLayout()
self.mainLayout.addLayout(self.hLayout)

and remove

和删除

self.mainLayout.show()

This should solve the issue .

这应该能解决这个问题。

#2


0  

The proto type of construct a QLayout is

构建QLayout的proto类型是。

def __init__(self, QWidget=None): # real signature unknown; restored from __doc__ with multiple overloads
    pass

so, you need to construct like this:

所以,你需要这样构造:

self.hLayout = QtGui.QHBoxLayout(self)