当前位置: 首页 > news >正文

做网站威海/百度seo最新算法

做网站威海,百度seo最新算法,外贸运输流程,网站开发mvc架构使用Python3.6.3 PyQt5.13.0 构建了一个无边框窗口可以使用。 支持鼠标边缘拖拽大小。 支持双击标题最大化和还原。 支持按住标题拖拽位置。 上图 包含了标题栏。中心窗口,状态栏。 下载源码资源py文件直接使用传送门 1 使用方式: from frame_less import Fram…

使用Python3.6.3
PyQt5.13.0

构建了一个无边框窗口可以使用。
支持鼠标边缘拖拽大小。
支持双击标题最大化和还原。
支持按住标题拖拽位置。
上图
在这里插入图片描述
包含了标题栏。中心窗口,状态栏。

下载源码资源py文件直接使用传送门

1 使用方式:

from frame_less import FrameLessWindow
fw = FrameLessWindow()
fw.show()

2 功能和API介绍:
最大化。最小化。关闭。

设置标题 fw.setWindowTitle(''要设置的标题)

设置图标 fw.setWindowIcon(QIcon('图标的路径'))

设置中心窗口 fw.set_center_widget(QWidgetObj)

移除状态栏 fw.remove_status_bar()

详细代码:
修改标题背景的颜色和最大小化按钮的颜色样式在TitleBar类QSS

# _*_ coding:utf-8 _*_
# ---------------------------
# Python_Version 3.6.3
# PyQt_Version  5.13.0
# Author: zizle
# Created: 2020-05-16
# ---------------------------
import os
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QLabel, QStatusBar, QStackedWidget
from PyQt5.QtGui import QPixmap, QFont, QEnterEvent, QPainter, QPen, QColor, QIcon
from PyQt5.QtCore import QMargins, Qtfrom frames.price_open_interest import PriceOpenInterest
from settings import BASE_DIRclass TitleBar(QWidget):"""主窗口无边框后使用的标题栏"""def __init__(self, *args, **kwargs):super(TitleBar, self).__init__(*args, **kwargs)self.setAttribute(Qt.WA_StyledBackground, True)  # 支持使用QSS设置背景self._mouse_pos = Nonelayout = QHBoxLayout(self)layout.setContentsMargins(QMargins(3, 3, 3, 3))layout.setSpacing(2)self.title_label = QLabel(self)self.title_label.setScaledContents(True)self.title_label.setFixedSize(20, 20)layout.addWidget(self.title_label, alignment=Qt.AlignLeft)  # 加入窗口图标self.title_text = QLabel(self)self.title_text.setFixedHeight(20)layout.addWidget(self.title_text, alignment=Qt.AlignLeft)  # 加入窗口文字layout.addStretch()self.minimum_button = QPushButton('0', self)self.maximum_button = QPushButton('1', self)self.close_button = QPushButton('r', self)layout.addWidget(self.minimum_button, alignment=Qt.AlignRight)layout.addWidget(self.maximum_button, alignment=Qt.AlignRight)layout.addWidget(self.close_button, alignment=Qt.AlignRight)font = QFont('webdings')  # 使用webding字体设置按钮的图标self.minimum_button.setFont(font)self.maximum_button.setFont(font)self.close_button.setFont(font)self.minimum_button.setFixedSize(20, 20)self.maximum_button.setFixedSize(20, 20)self.close_button.setFixedSize(20, 20)self.minimum_button.clicked.connect(self.window_minimum)  # 设置点击的信号事件self.maximum_button.clicked.connect(self.window_maximum)self.close_button.clicked.connect(self.window_close)# 设置objectName来设置样式self.setObjectName('titleBar')self.minimum_button.setObjectName('minimumButton')self.maximum_button.setObjectName('maximumButton')self.close_button.setObjectName('closeButton')self.setStyleSheet("""#titleBar{background-color: rgb(34,102,175);}#minimumButton,#maximumButton,#closeButton {border: none;background-color: rgb(34,102,175);}#minimumButton:hover,#maximumButton:hover {color: rgb(33,165,229);}#closeButton:hover {color: rgb(200,49,61);}""")self.setLayout(layout)def mouseDoubleClickEvent(self, event):self.window_maximum()event.accept()  # 接受事件,禁止传到父控件# 鼠标移动def mouseMoveEvent(self, event):if event.buttons() == Qt.LeftButton and self._mouse_pos:self.parent().move(self.mapToGlobal(event.pos() - self._mouse_pos))event.accept()  # 接受事件,不传递到父控件def mousePressEvent(self, event):if event.button() == Qt.LeftButton:self._mouse_pos = event.pos()event.accept()  # 接受事件,不传递到父控件def mouseReleaseEvent(self, event):self._mouse_pos = Noneevent.accept()  # 接受事件,不传递到父控件def window_minimum(self):self.parent().showMinimized()def window_maximum(self):if self.maximum_button.text() == '1':self.maximum_button.setText('2')self.parent().showMaximized()else:self.maximum_button.setText('1')self.parent().showNormal()def window_close(self):self.parent().close()def set_window_title(self, title):self.title_text.setText(title)def set_window_icon(self, pix_map):if isinstance(pix_map, QPixmap):self.title_label.setPixmap(pix_map)class CenterWidget(QStackedWidget):def __init__(self, *args, **kwargs):super(CenterWidget, self).__init__(*args, **kwargs)self.setAutoFillBackground(True)def clear(self):for i in range(self.count()):widget = self.widget(i)self.removeWidget(widget)if widget is not None:widget.deleteLater()del widgetclass StatusBar(QStatusBar):def __init__(self, *args, **kwargs):super(StatusBar, self).__init__(*args, **kwargs)self.setAutoFillBackground(True)class FrameLessWindow(QWidget):"""主窗口"""MARGIN = 5Left, Top, Right, Bottom, LeftTop, RightTop, LeftBottom, RightBottom = range(8)def __init__(self, *args, **kwargs):super(FrameLessWindow, self).__init__(*args, **kwargs)self.resize(1200, 680)self.setWindowFlags(Qt.FramelessWindowHint)  # 无边框self.setAttribute(Qt.WA_TranslucentBackground, True)self.setMouseTracking(True)  # 鼠标追踪,mouseMoveEvent才有效果self._direction = None  # 此时鼠标的方向self._pressed = False  # 鼠标是否按下self._mouse_pos = None  # 记录鼠标位置layout = QVBoxLayout(self)layout.setSpacing(0)layout.setContentsMargins(QMargins(self.MARGIN, self.MARGIN, self.MARGIN, self.MARGIN))self.title = TitleBar(self)self.title.installEventFilter(self)  # 安装事件过滤,进入控件还原方向和鼠标状态layout.addWidget(self.title, alignment=Qt.AlignTop)self.center_widget = CenterWidget(self)self.center_widget.installEventFilter(self)layout.addWidget(self.center_widget)self.status_bar = StatusBar(self)self.status_bar.installEventFilter(self)layout.addWidget(self.status_bar, alignment=Qt.AlignBottom)self.setLayout(layout)def eventFilter(self, obj, event):if isinstance(event, QEnterEvent):self.setCursor(Qt.ArrowCursor)self._direction = None  # 去除方向self._pressed = None  # 去除按下标记return super(FrameLessWindow, self).eventFilter(obj, event)def mousePressEvent(self, event):super(FrameLessWindow, self).mousePressEvent(event)if event.button() == Qt.LeftButton:self._mouse_pos = event.pos()self._pressed = Truedef mouseReleaseEvent(self, event):super(FrameLessWindow, self).mouseReleaseEvent(event)self._pressed = Falseself._direction = Nonedef mouseMoveEvent(self, event):super(FrameLessWindow, self).mouseMoveEvent(event)pos = event.pos()pos_x, pos_y = pos.x(), pos.y()wm, hm = self.width() - self.MARGIN, self.height() - self.MARGIN# print(wm, hm)# 窗口最大无需事件if self.isMaximized() or self.isFullScreen():self._direction = Noneself.setCursor(Qt.ArrowCursor)returnif event.buttons() == Qt.LeftButton and self._pressed:self.resize_window(pos)if pos_x <= self.MARGIN and pos_y <= self.MARGIN:# 左上角self._direction = self.LeftTopself.setCursor(Qt.SizeFDiagCursor)elif wm <= pos_x <= self.width() and hm <= pos_y <= self.height():# 右下角self._direction = self.RightBottomself.setCursor(Qt.SizeFDiagCursor)elif wm <= pos_x and pos_y <= self.MARGIN:# 右上角self._direction = self.RightTopself.setCursor(Qt.SizeBDiagCursor)elif pos_x <= self.MARGIN and hm <= pos_y:# 左下角self._direction = self.LeftBottomself.setCursor(Qt.SizeBDiagCursor)elif 0 <= pos_x <= self.MARGIN <= pos_y <= hm:# 左边self._direction = self.Leftself.setCursor(Qt.SizeHorCursor)elif wm <= pos_x <= self.width() and self.MARGIN <= pos_y <= hm:# 右边self._direction = self.Rightself.setCursor(Qt.SizeHorCursor)elif wm >= pos_x >= self.MARGIN >= pos_y >= 0:# 上面self._direction = self.Topself.setCursor(Qt.SizeVerCursor)elif self.MARGIN <= pos_x <= wm and hm <= pos_y <= self.height():# 下面self._direction = self.Bottomself.setCursor(Qt.SizeVerCursor)else:passdef showMaximized(self):super(FrameLessWindow, self).showMaximized()self.layout().setContentsMargins(0, 0, 0, 0)def showNormal(self):super(FrameLessWindow, self).showNormal()self.layout().setContentsMargins(self.MARGIN, self.MARGIN, self.MARGIN, self.MARGIN)def paintEvent(self, event):super(FrameLessWindow, self).paintEvent(event)painter = QPainter(self)painter.setPen(QPen(QColor(200, 200, 200, 1), 2 * self.MARGIN))painter.drawRect(self.rect())def setWindowTitle(self, title):super(FrameLessWindow, self).setWindowTitle(title)self.title.set_window_title(title)def setWindowIcon(self, icon):if isinstance(icon, QIcon):super(FrameLessWindow, self).setWindowIcon(icon)self.title.set_window_icon(icon.pixmap(20, 20))def resize_window(self, pos):if self._direction is None:returnmpos = pos - self._mouse_posxPos, yPos = mpos.x(), mpos.y()geometry = self.geometry()x, y, w, h = geometry.x(), geometry.y(), geometry.width(), geometry.height()if self._direction == self.LeftTop:  # 左上角if w - xPos > self.minimumWidth():x += xPosw -= xPosif h - yPos > self.minimumHeight():y += yPosh -= yPoselif self._direction == self.RightBottom:  # 右下角if w + xPos > self.minimumWidth():w += xPosself._mouse_pos = posif h + yPos > self.minimumHeight():h += yPosself._mouse_pos = poselif self._direction == self.RightTop:  # 右上角if h - yPos > self.minimumHeight():y += yPosh -= yPosif w + xPos > self.minimumWidth():w += xPosself._mouse_pos.setX(pos.x())elif self._direction == self.LeftBottom:  # 左下角if w - xPos > self.minimumWidth():x += xPosw -= xPosif h + yPos > self.minimumHeight():h += yPosself._mouse_pos.setY(pos.y())elif self._direction == self.Left:  # 左边if w - xPos > self.minimumWidth():x += xPosw -= xPoselse:returnelif self._direction == self.Right:  # 右边if w + xPos > self.minimumWidth():w += xPosself._mouse_pos = poselse:returnelif self._direction == self.Top:  # 上面if h - yPos > self.minimumHeight():y += yPosh -= yPoselse:returnelif self._direction == self.Bottom:  # 下面if h + yPos > self.minimumHeight():h += yPosself._mouse_pos = poselse:returnself.setGeometry(x, y, w, h)def remove_status_bar(self):self.status_bar.hide()def set_center_widget(self, widget):self.center_widget.clear()self.center_widget.addWidget(widget)
http://www.lbrq.cn/news/1261477.html

相关文章:

  • 金融适合什么颜色做网站/手机自动排名次的软件
  • 旅游模板网站建设/宁波抖音seo搜索优化软件
  • 工厂网站建设/学电脑在哪里报名
  • wordpress菜单导航插件/武汉久都seo
  • 网站建站素材/北京疫情又严重了
  • 溧阳做网站/公关公司经营范围
  • 水果网络营销策划书/windows优化
  • 成都小程序系统定制开发/当阳seo外包
  • 宜兴做网站多少钱/郑州搜狗关键词优化顾问
  • wordpress免ftp/seo怎么才能优化好
  • 惠州网站建设设计/外链代发
  • 郑州免费自助建站模板/广告位招商怎么找客户
  • 可信赖的南昌网站制作/seo排名计费系统
  • 北京网站建设推荐q479185700上快/好看的seo网站
  • 网站开发都有/电商seo优化是什么意思
  • 网站开发设计师培训/网站技术解决方案
  • wordpress变成小程序/深圳网站设计专业乐云seo
  • nginx环境下安装wordpress/合肥网站优化推广方案
  • 网站广告位投放/搜索引擎营销方法有哪些
  • 网站开发中数据库的设计原则/职业培训热门行业
  • 网站域名申请/考拉seo
  • 有哪些h5做的网站/站长工具在线平台
  • 交友系统网站建设/宁波网站建设与维护
  • 产品外观设计师/seo网站优化师
  • 网站建设论文linux/关键词优化需要从哪些方面开展?
  • 网站建设论文答辩自述/什么软件可以推广自己的产品
  • 网站主服务器所在地地址/微信管理软件哪个最好
  • ag bbin 网站开发/建站官网
  • 网站建设经验心得/百度指数网址
  • 网站备案要什么资料/专注于品牌营销服务
  • Petalinux快捷下载
  • vue3+vue-flow制作简单可拖拽可增删改流程图
  • 研报复现|史蒂夫·路佛价值选股法则
  • [硬件电路-138]:模拟电路 - 什么是正电源?什么是负电源?集成运放为什么有VCC+和VCC-
  • 关于assert()函数,eval()函数,include
  • Spring lookup-method实现原理深度解析