Pyqt python 界面代码

1、界面拖动代码

python 复制代码
# 拖动
def mousePressEvent(self, event):
    if event.button() == QtCore.Qt.LeftButton and self.isMaximized() == False:
        self.m_flag = True
        self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
        event.accept()
        self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))  # 更改鼠标图标
def mouseMoveEvent(self, mouse_event):
    if QtCore.Qt.LeftButton and self.m_flag:
        self.move(mouse_event.globalPos() - self.m_Position)  # 更改窗口位置
        mouse_event.accept()
def mouseReleaseEvent(self, mouse_event):
    self.m_flag = False
    self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))

2、获取显示器分辨率

python 复制代码
#获取显示器分辨率
self.desktop = QApplication.desktop()
self.screenRect = self.desktop.screenGeometry()
self.screenheight = self.screenRect.height()
self.screenwidth = self.screenRect.width()

3、pyqt界面随界面大小变化图标

python 复制代码
# 变换最大化按钮图标
def resize_win(self):
    if self.isFullScreen():
        self.showNormal()
        self.ui.pushButton_maxsize.setIcon(QtGui.QIcon(u":/icon/icon/全屏黑.png"))
        Width_value = self.ui.label_show_camera.height()
        self.Width_fy = Width_value / 720
    else:
        self.showFullScreen()
        self.ui.pushButton_maxsize.setIcon(QtGui.QIcon(u":/icon/icon/最小化黑.png"))
        Width_value = self.ui.label_show_camera.height()
        self.Width_fy = Width_value / 720

4、侧边栏随动代码

python 复制代码
# 设置侧边伸缩菜单
def slideLeftMenu(self):
    width = self.ui.frame.width()
    if width == 46:
        newWidth = 130
        self.ui.pushButton.setIcon(QIcon(":/icons/icon/双左_double-left.png"))
    else:
        newWidth = 46
        self.ui.pushButton.setIcon(QIcon(":/icons/icon/双右_double-right.png"))
    animation = QPropertyAnimation(self.ui.frame, b"minimumWidth", self)
    animation.setStartValue(width)
    animation.setEndValue(newWidth)
    animation.setDuration(200)
    animation.start()

5、设置保存,加载上次保存设置

python 复制代码
# 加载上次登录信息
def read_config_info(self):
    settings = QSettings("config.ini", QSettings.IniFormat)  # 方法1:使用配置文件
    # self.ui.lineEdit_list_fxdpath.setText(settings.value("page_list/filename_fxd"))  # 包装程序时记得注释此行
    self.ui.lineEdit_list_xhdpath.setText(settings.value("page_list/filename_xhd"))
    self.ui.lineEdit_list_bgpath.setText(settings.value("page_list/foldername_bg"))
    self.ui.lineEdit_list_qzr.setText(settings.value("page_list/qzrname"))

# 保存上次登录设置信息
def save_config_info(self):
    settings = QSettings("config.ini", QSettings.IniFormat)  # 方法1:使用配置文件
    # settings = QSettings("mysoft","myapp")                        #方法2:使用注册表
    # settings.setValue("page_list/filename_fxd", self.ui.lineEdit_list_fxdpath.text())  # 包装程序时记得注释此行
    settings.setValue("page_list/filename_xhd", self.ui.lineEdit_list_xhdpath.text())
    settings.setValue("page_list/foldername_bg", self.ui.lineEdit_list_bgpath.text())
    settings.setValue("page_list/qzrname", self.ui.lineEdit_list_qzr.text())
相关推荐
宝贝儿好4 天前
【python】第五章:python-GUI编程
python·pyqt
Goona_5 天前
PyQt批量年龄计算工具:从身份证到指定日期的周岁处理
python·小程序·交互·pyqt
AI视觉网奇6 天前
pyqt 触摸屏监听
开发语言·python·pyqt
感谢地心引力9 天前
【Python】基于 PyQt6 和 Conda 的 PyInstaller 打包工具
数据库·python·conda·pyqt·pyinstaller
AntBlack10 天前
PyQtInspect : 推荐一个好用的 PythonQT 界面 Debug 工具
python·pyqt
开心-开心急了12 天前
PySide6 文本编辑器(QPlainTextEdit)实现查找功能——重构版本
开发语言·python·ui·重构·pyqt
开心-开心急了14 天前
主窗口(QMainWindow)如何放入文本编辑器(QPlainTextEdit)等继承自QWidget的对象--(重构版)
python·ui·pyqt
AI视觉网奇14 天前
pyqt 播放视频遮罩显示 时钟
音视频·pyqt
开心-开心急了16 天前
PySide6 打印(QPrinter)文本编辑器(QPlaintextEdit)内容
python·ui·pyqt
CAE虚拟与现实18 天前
PyQt和PySide中使用Qt Designer
开发语言·qt·pyqt·qt designer·pyside