python - PyQt4 : check the window is existing or not

标签 python pyqt pyqt4 instance

我为 MAYA 制作了一种工具。 一旦我调用了这个类并创建了一个实例,我就不必再调用它了。 相反,我必须检查窗口是否存在。 事实上,当我按下按钮调用 close() 或“X”按钮时,它不会调用 __del()__ 方法。我无法清理我的作品。

所以,我打算检查实例是否存在,如果存在,我不调用类,只调用show()。 但是,我找不到路。

_win = RigControlWindow()
_win.show()

RigControlWindow 类如何找到实例存在?

最佳答案

保留对 RigControlWindow 实例的引用作为主窗口的私有(private)属性。

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self._rcwin = None

    def showRigControlWindow(self):
        if self._rcwin is None:
            self._rcwin = RigControlWindow()
        self._rcwin.show()

或者,您可以使用属性:

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self._rcwin = None

    @property    
    def rcwin(self):
        if self._rcwin is None:
            self._rcwin = RigControlWindow()
        return self._rcwin

    def showRigControlWindow(self):
        self.rcwin.show()

关于python - PyQt4 : check the window is existing or not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8584526/

相关文章:

python - pickle 模块错误。属性错误 : class has no attribute '__new__'

python - 在 64 位 Windows 上安装 SetupTools

python - 如何复制QtableWidget的一行并插入到它下面的行?

python - PyQt 声子音频播放器

python - 选择 QCompleter 项目后无法清除 QLineEdit

python - pyQt QTableView 选择一组不连续的行

Python - 如何检查列表单调性

python - Python线程名称未显示在ps或htop上

python - PyQt 更新 QTableWidget 中的某个单元格

python - 在pyqt中选择单选按钮时更改lineEdit的文本