PySide6隐藏和显示窗口(QWidget)

PySide6.QtWidgets.QWidget类的成员函数hide()可用于隐藏窗口,show()可用于显示窗口;

隐藏窗口

hide()可用于隐藏窗口;窗口只是不可见,并没有被销毁;

显示窗口

show()可用于显示一个窗口实例;

示例代码

import sys
from PySide6 import QtCore, QtWidgets, QtGui
import time

class MyWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()

        self.button = QtWidgets.QPushButton("隐藏窗口")

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.addWidget(self.button)

        self.button.clicked.connect(self.hideandshow)

    @QtCore.Slot()
    def hideandshow(self):
        self.hide() #隐藏Widget
        print("已隐藏Widget,5秒后显示")
        time.sleep(5)
        self.show() #显示Widget

if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    widget = MyWidget()
    widget.resize(300, 200)

    widget.show()

    sys.exit(app.exec())

原创内容,如需转载,请注明出处;

本文地址: https://www.perfcode.com/p/pyside6-qtwidgets-qwidget-hide-and-show.html

分类: 计算机技术
推荐阅读:
Python 实现哈希表 哈希表是一种数据结构,其中数据元素的地址或索引值是从哈希函数生成的。在Python中,Dictionary数据类型就是哈希表的实现。
Python ascii()函数 ascii()是 Python 内置函数之一,它可以将一个对象转换为ASCII字符串表示。
提示Permission denied的解决方法 通常,提示Permission denied表示你的某个操作权限不够;在Linux系统中,权限分为读权限、写权限和可执行权限,当你所在的用户组没有相关权限时,则会提示Permission denied;
Golang实现线性搜索算法(Linear Search) 本文将使用Go语言实现线性搜索算法(Linear Search);
Rust:variable does not need to be mutable警告解决方法 在Rust中,当你使用了mut关键字声明变量,但你后面的代码并没对该关键字进行修改,则rust编译器会产生 variable does not need to be mutable 的警告提示;
没有main()函数的C语言程序 有两种方法可以不添加main()函数来运行C语言程序,第一种用#define预处理指令,第二种是使用-nostartfiles编译选项;