吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 403|回复: 3
收起左侧

[求助] python的pyside6无法正确使用qt designer导出的py文件

[复制链接]
sakura32 发表于 2024-4-11 08:58
pyside6的版本为 6.7.0
使用qt designer画了个只有一个button和一个布局的ui后,导出py代码
使用如下代码加载该.py文件
[Python] 纯文本查看 复制代码
class MyWindow(QMainWindow):
 def __init__(self):
    super().__init__()
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)


报错
[Python] 纯文本查看 复制代码
TypeError: 'PySide6.QtWidgets.QBoxLayout.addLayout' called with wrong argument types:
  PySide6.QtWidgets.QBoxLayout.addLayout(QVBoxLayout)
Supported signatures:
  PySide6.QtWidgets.QBoxLayout.addLayout(PySide6.QtWidgets.QLayout, int = 0)


有没有大佬知道这个是什么原因报错,之前用的pyside6版本6.1.3的时候这种用法是可行的,是最新版更新用法了吗

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

H1314 发表于 2024-4-11 09:45
妙 不错很好用的

免费评分

参与人数 1吾爱币 -15 收起 理由
爱飞的猫 -15 警告:求助版块禁止回复与主题无关非技术内容,违者重罚!

查看全部评分

爱喝牛奶的小孩 发表于 2024-4-11 10:19
错误信息 TypeError: 'PySide6.QtWidgets.QBoxLayout.addLayout' called with wrong argument types
表明你在尝试将一个 QVBoxLayout 对象添加到 QBoxLayout 中,但是 addLayout 方法的参数类型不匹配。
在 PySide6 6.7.0 版本中, QBoxLayout.addLayout 方法可能只接受 QLayout 类型的参数,而你传入的 QVBoxLayout 虽然继承自 QLayout,但可能不被视为相同类型。

有几种方法可以尝试解决这个问题:
1. 强制转换类型: 尝试将 QVBoxLayout 对象转换为 QLayout 类型,再将其添加到 QBoxLayout 中。例如:
[Python] 纯文本查看 复制代码
layout = self.ui.verticalLayout  # 假设verticalLayout是QVBoxLayout对象
self.ui.horizontalLayout.addLayout(QLayout(layout))  # 将verticalLayout转换为QLayout

2. 使用addItem: 如果你的 QBoxLayout 是水平或垂直布局,可以尝试使用 addItem 方法添加控件,而不是添加布局。例如:
[Python] 纯文本查看 复制代码
button = QPushButton("按钮")
self.ui.horizontalLayout.addWidget(button)


建议查看官方文档

我心飞翔1995 发表于 2024-4-11 15:28
爱喝牛奶的小孩 发表于 2024-4-11 10:19
错误信息 TypeError: 'PySide6.QtWidgets.QBoxLayout.addLayout' called with wrong argument types
表明 ...

实测不需要转换
[Python] 纯文本查看 复制代码
from PySide6 import QtWidgets
b = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.Direction.LeftToRight)
a = QtWidgets.QVBoxLayout()
b.addLayout(a)
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-2 19:07

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表