Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x PySide2/QLayout:无法将空布局添加到QHBoxLayout_Python 3.x_Pyside2_Qvboxlayout - Fatal编程技术网

Python 3.x PySide2/QLayout:无法将空布局添加到QHBoxLayout

Python 3.x PySide2/QLayout:无法将空布局添加到QHBoxLayout,python-3.x,pyside2,qvboxlayout,Python 3.x,Pyside2,Qvboxlayout,我想用PySide2创建一个QHBoxLayout,它的子级是2个QVBoxLayout。 为了便于阅读,我想在不同的功能(左面板和右面板)中分离2个QVBoxLayout 请在下面找到脚本的示例 import sys from PySide2 import QtCore, QtGui from PySide2.QtWidgets import (QVBoxLayout, QTableWidget, QWidget, QLabel, QLineEdit, QPushButton, QCheckB

我想用PySide2创建一个QHBoxLayout,它的子级是2个QVBoxLayout。 为了便于阅读,我想在不同的功能(左面板和右面板)中分离2个QVBoxLayout

请在下面找到脚本的示例

import sys
from PySide2 import QtCore, QtGui
from PySide2.QtWidgets import (QVBoxLayout, QTableWidget, QWidget, QLabel, QLineEdit, QPushButton, QCheckBox,
                             QTextEdit, QGridLayout, QApplication, QAbstractItemView, QHBoxLayout)

class Example(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        mainLayout = QHBoxLayout()

        mainLayout.addLayout(self.left_panel())
        mainLayout.addLayout(self.right_panel())
        self.setLayout(mainLayout)

    def right_panel(self):
        rightLayout = QVBoxLayout()

        self.tableCert = QTableWidget()
        self.tableCert.setColumnCount(3)
        self.tableCertColumnLabels = ["First Name","Surname","login"]
        self.tableCert.setRowCount(2)
        self.tableCert.setHorizontalHeaderLabels(self.tableCertColumnLabels)
        self.tableCert.verticalHeader().setVisible(False)
        self.tableCert.horizontalHeader().setVisible(True)     
        rightLayout.addWidget(self.tableCert)
    
    def left_panel(self):
        pass #Here we will have the content of the other QVBoxLayout

def main():
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
问题是,当我执行脚本时,出现以下错误:

QLayout: Cannot add a null layout to QHBoxLayout
你知道我为什么要纠正这个问题吗


提前谢谢。

问题很简单:
右面板
方法不返回任何内容,或者说不返回任何内容,因此:

mainLayout.addLayout(self.right_panel())
相当于Y:

mainLayout.addLayout(None)
解决方案是返回rightLayout:

def right_panel(self):
    rightLayout = QVBoxLayout()

    self.tableCert = QTableWidget()
    self.tableCert.setColumnCount(3)
    self.tableCertColumnLabels = ["First Name", "Surname", "login"]
    self.tableCert.setRowCount(2)
    self.tableCert.setHorizontalHeaderLabels(self.tableCertColumnLabels)
    self.tableCert.verticalHeader().setVisible(False)
    self.tableCert.horizontalHeader().setVisible(True)
    rightLayout.addWidget(self.tableCert)
    return rightLayout
def右面板(自):
rightLayout=QVBoxLayout()
self.tableCert=QTableWidget()
self.tableCert.setColumnCount(3)
self.tableCertColumnLabels=[“名字”、“姓氏”、“登录名”]
self.tableCert.setRowCount(2)
self.tableCert.setHorizontalHeaderLabels(self.tableCertColumnLabels)
self.tableCert.verticalHeader().setVisible(False)
self.tableCert.horizontalHeader().setVisible(True)
rightLayout.addWidget(self.tableCert)

return rightLayout
问题很简单:
right\u面板
方法不返回任何内容,或者说不返回任何内容,因此:

mainLayout.addLayout(self.right_panel())
相当于Y:

mainLayout.addLayout(None)
解决方案是返回rightLayout:

def right_panel(self):
    rightLayout = QVBoxLayout()

    self.tableCert = QTableWidget()
    self.tableCert.setColumnCount(3)
    self.tableCertColumnLabels = ["First Name", "Surname", "login"]
    self.tableCert.setRowCount(2)
    self.tableCert.setHorizontalHeaderLabels(self.tableCertColumnLabels)
    self.tableCert.verticalHeader().setVisible(False)
    self.tableCert.horizontalHeader().setVisible(True)
    rightLayout.addWidget(self.tableCert)
    return rightLayout
def右面板(自):
rightLayout=QVBoxLayout()
self.tableCert=QTableWidget()
self.tableCert.setColumnCount(3)
self.tableCertColumnLabels=[“名字”、“姓氏”、“登录名”]
self.tableCert.setRowCount(2)
self.tableCert.setHorizontalHeaderLabels(self.tableCertColumnLabels)
self.tableCert.verticalHeader().setVisible(False)
self.tableCert.horizontalHeader().setVisible(True)
rightLayout.addWidget(self.tableCert)
返回右布局