Пример #1
0
def start():
    app = QSingleApplication("zzclient", sys.argv)
    # 异常捕获
    os.makedirs(Config().except_path, exist_ok=True)
    sys.excepthook = cgitb.Hook(1, Config().except_path, 5, sys.stderr, '')
    if app.isRunning():
        # 激活窗口
        app.sendMessage('show', 1000)
    else:
        # 窗口关闭程序退出
        app.setQuitOnLastWindowClosed(True)
        # 应用图标
        app.setWindowIcon(ResourceLoader().qt_icon_project_ico)
        # 设置主题样式
        Theme.load()
        # 设置字体
        # fontDB = QFontDatabase()
        # fontDB.addApplicationFont(':/font/Roboto-Regular.ttf')
        # app.setFont(QFont('Roboto'))
        # 设置雅黑字体
        app.setFont(ResourceLoader.load_app_font())
        # 图标字体
        ResourceLoader.load_icon_font()
        # 加载模块
        ResourceLoader.load_modules()
        # 创建窗体
        window = HomePage()
        window.resize(1024 ,768)
        # 样式注入器
        ConnectStyleSheetInspector(main_window=window,
                                   shortcut=QKeySequence(Qt.Key_Tab))
        # 计算居中显示的位置
        desktop = QDesktopWidget().availableGeometry()
        width = (desktop.width() - window.width()) / 2
        height = (desktop.height() - window.height()) / 2
        app.setActivationWindow(window)
        window.show()
        window.move(width, height)
        sys.exit(app.exec_())
Пример #2
0
Window {
    background-color: #282C34;   
}
'''


class Window(QWidget):
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)

        self.resize(500, 500)
        self.setStyleSheet(Style)
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        QTimer.singleShot(400, lambda: Toast.showTip("这是一条提示"))
        QTimer.singleShot(2000, lambda: Toast.showTip("这是一条提示"))

    def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
        Bloc_App().app_closed.emit()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    Theme.load()
    app.setFont(ResourceLoader.load_app_font())
    window = Window()
    window.show()

    sys.exit(app.exec_())