weixin_41876805 2023-04-18 17:40 采纳率: 40%
浏览 42

Pyside6加载QMessageBox时报错

ui转换为py文件后,在进行初始化没有问题,但是加载QMessageBox时报错。

from PySide6.QtWidgets import QApplication,QMessageBox,QMainWindow
from ui.patinfo_search import *
import sys


class UI(QMainWindow,Ui_Form):
    def __init__(self,parent = None):
        super(UI,self).__init__(parent)
        # 子类继承了父类的所有属性和方法,父类属性自然会用父类方法来进行初始化
        self.ui = Ui_Form() # 来自 patinfo_search.py 中的类。
        self.ui.setupUi(self)
        self.ui.button1.clicked.connect(self.yahoo)
        self.ui.button2.clicked.connect(self.copy)

    def yahoo(self):
        print('button1 was be knocked')
        QMessageBox.about(self.ui,'反馈结果','hello hello hello')

    def copy(self):
        print('button1 was be knocked')
        info = self.ui.textedit1.toPlainText()
        QMessageBox.about(self.ui,'复制结果',f'{info}')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    uiui = UI()
    uiui.show()
    sys.exit(app.exec_())

py文件

# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'patinfo_search.ui'
##
## Created by: Qt User Interface Compiler version 6.4.3
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
    QMetaObject, QObject, QPoint, QRect,
    QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
    QFont, QFontDatabase, QGradient, QIcon,
    QImage, QKeySequence, QLinearGradient, QPainter,
    QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QPlainTextEdit, QPushButton, QSizePolicy,
    QWidget)

class Ui_Form(object):
    def setupUi(self, Form):
        if not Form.objectName():
            Form.setObjectName(u"Form")
        Form.resize(737, 556)
        self.button1 = QPushButton(Form)
        self.button1.setObjectName(u"button1")
        self.button1.setGeometry(QRect(490, 150, 81, 31))
        self.button2 = QPushButton(Form)
        self.button2.setObjectName(u"button2")
        self.button2.setGeometry(QRect(490, 270, 81, 31))
        self.textedit1 = QPlainTextEdit(Form)
        self.textedit1.setObjectName(u"textedit1")
        self.textedit1.setGeometry(QRect(120, 90, 291, 281))

        self.retranslateUi(Form)

        QMetaObject.connectSlotsByName(Form)
    # setupUi

    def retranslateUi(self, Form):
        Form.setWindowTitle(QCoreApplication.translate("Form", u"patinfo_search", None))
        self.button1.setText(QCoreApplication.translate("Form", u"\u70b9\u51fb\u6d4b\u8bd5", None))
        self.button2.setText(QCoreApplication.translate("Form", u"\u83b7\u53d6\u4fe1\u606f", None))
    # retranslateUi



点击按钮后提示:

TypeError: 'PySide6.QtWidgets.QMessageBox.about' called with wrong argument types:
  PySide6.QtWidgets.QMessageBox.about(Ui_Form, str, str)
Supported signatures:
  PySide6.QtWidgets.QMessageBox.about(PySide6.QtWidgets.QWidget, str, str)

  • 写回答

2条回答 默认 最新

  • 于扶摇 2023-04-19 11:41
    关注

    这可能是因为您在初始化QMessageBox时使用了不正确的参数。请确保在初始化QMessageBox时传递正确的参数,例如:QMessageBox.about(self.ui,'反馈结果','hello hello hello', QMessageBox.Yes | QMessageBox.No)这将使QMessageBox显示“是”或“否”选项,而不是默认的“确定”和“取消”选项

    评论

报告相同问题?

问题事件

  • 创建了问题 4月18日

悬赏问题

  • ¥15 短剧的sdk在哪里接入
  • ¥15 求:可不可以提供一些 在国内可以用,低代码不要太难 在电脑上可以下载的 制作app的软件
  • ¥60 找人回答kibana8.14.3二次集成开发,自定义插件ui导航栏如何设置
  • ¥15 fluke高精度万用表8845A型号测交流电压一直跳动,且去掉输入后显示不归零
  • ¥15 不同模型怎么用同一个shader
  • ¥15 安卓启动没有ais proxy与v4l2的log打印
  • ¥15 go怎么读取mdb文件里面的数据
  • ¥60 Matlab联合CRUISE仿真编译dll文件报错
  • ¥15 脱敏项目合作,ner需求合作
  • ¥15 脱敏项目合作,ner需求合作