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())
相关推荐
OICQQ676580084 天前
创建一个基于YOLOv8+PyQt界面的驾驶员疲劳驾驶检测系统 实现对驾驶员疲劳状态的打哈欠检测,头部下垂 疲劳眼睛检测识别
yolo·pyqt·疲劳驾驶·检测识别·驾驶员检测·打哈欠检测·眼睛疲劳
小灰灰搞电子13 天前
Qt PyQt与PySide技术-C++库的Python绑定
c++·qt·pyqt
越甲八千14 天前
pyqt 简单条码系统
数据库·microsoft·pyqt
重生之我在厦门做测试16 天前
基于pyqt开发串口和对应映射值(path)的显示工具
pyqt
hvinsion19 天前
【开源解析】基于Python+Qt打造智能应用时长统计工具 - 你的数字生活分析师
python·pyqt·开源软件·应用时长统计
毕设做完了吗?21 天前
基于YOLOv8+Deepface的人脸检测与识别系统
python·yolo·毕业设计·pyqt
懷淰メ1 个月前
python3GUI--基于PyQt5+DeepSort+YOLOv8智能人员入侵检测系统(详细图文介绍)
开发语言·深度学习·yolo·目标检测·pyqt·课程设计·deepsort
Humbunklung1 个月前
PySide6 GUI 学习笔记——常用类及控件使用方法(多行文本控件QTextEdit)
笔记·python·学习·pyqt
En^_^Joy1 个月前
PyQt常用控件的使用:QFileDialog、QMessageBox、QTreeWidget、QRadioButton等
开发语言·python·pyqt
zhlei_123451 个月前
封闭内网安装配置VSCode Anconda3 并配置 PyQt5开发
ide·vscode·pyqt