如何关闭 QDialog [英] How to close a QDialog

查看:175
本文介绍了如何关闭 QDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试关闭从主窗口分支出来的 QDialog 窗口.到目前为止,以下内容对我不起作用:

I've been trying to close a QDialog window that is branching off of my main window. The following have not worked for me so far:

self.close()
QDialog.close()

我尝试了其他命令,例如 exitexec_() ,但没有成功.我得到的最常见的错误是

I tried other commands such as exit and exec_() with no luck. The most common error I get is

[className] 对象没有属性 'close'

[className] object has no attribute 'close'

# Creating our window
class Ui_MainWindow(object):

    # Sets up GUI
    def setupUi(self, MainWindow):

        [GUI CODE]      

    # Sets text for parts of GUI
    def retranslateUi(self, MainWindow):

        [MORE GUI CODE]

    # Function handling screencap on click and metadata for filenames
    def cap_on_Click(arg1,arg2):

        popup = QDialog()
        popup_ui = Ui_Dialog()
        popup_ui.setupUi(popup)
        popup.show()
        sys.exit(popup.exec_())

上面是我的主窗口

class Ui_Dialog(object):

    def setupUi(self, Dialog):

        [GUI CODE]

    def retranslateUi(self, Dialog):

        [MORE GUI CODE]

    def button_click(self, arg1):

        self.close()

第二块是对话窗口代码.如何关闭此对话窗口?

The second block is the dialog window code. How do I close this dialog window?

推荐答案

首先对 C++ 相关的链接表示抱歉,但是 Python 具有相同的概念.

First of all, sorry for the links related to C++, but Python has the same concept.

您可以尝试使用rejectacceptdone 函数关闭对话框.通过这样做,您可以适当地设置返回值(RejectedAccepted 或您指定为参数的那个).

You can try using the reject or accept or done function to close the dialog box. By doing this, you're setting the return value appropriately (Rejected, Accepted or the one you specify as the argument).

总而言之,您应该尝试调用 YourDialog.done(n) 关闭对话框并返回 nYourDialog.accept()> 或 YourDialog.reject() 当您希望它被接受/拒绝时.

All in all, you should try calling YourDialog.done(n) to close the dialog and return n and YourDialog.accept() or YourDialog.reject() when you want it accepted/rejected.

这篇关于如何关闭 QDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆