产品展示网站含后台网站模板下载,福田公司名称及地址,app 制作,大连网站推广优化控件旋转角度#xff0c;并跟随缩放改变大小 背景使用控件结果 背景
一个项目需求#xff0c;需要旋转某个控件90使用#xff0c;在网上找了很多资料#xff0c;没有特别合适的#xff0c;自己试水试了一天半#xff0c;终于弄了个大概其#xff0c;特此记录
使用控件… 控件旋转角度并跟随缩放改变大小 背景使用控件结果 背景
一个项目需求需要旋转某个控件90使用在网上找了很多资料没有特别合适的自己试水试了一天半终于弄了个大概其特此记录
使用控件
GraphicsView试图QGraphicsScene(场景)QGraphicsProxyWidget实现旋转 主要就是往GraphicsView试图 里面的 QGraphicsScene(场景)添加一个可以旋转的控件QGraphicsProxyWidget然后旋转试图实现控件旋转通过试图的fitInView函数实现控件缩放。 然后出先了个问题 不能跟随界面大小自动变化。解决办法,自定义一个GraphicsView类重写resizeEvent方法
结果 缩放后 from PyQt5.QtWidgets import QApplication, QGraphicsScene, QGraphicsView, QLabel, QGraphicsProxyWidget, QVBoxLayout, \QWidget
from PyQt5.QtCore import Qt
from jys.pyqtwidget.pyqtchart_handel import ChartBaseclass CustomGraphicsView(QGraphicsView):def resizeEvent(self, event):super().resizeEvent(event)self.fitInView(self.scene().sceneRect(), Qt.KeepAspectRatio)app QApplication([])
scene QGraphicsScene()
view CustomGraphicsView()
view.setScene(scene)
# 创建一个QLabel并将其作为子部件添加到QGraphicsProxyWidget
label ChartBase()
proxy QGraphicsProxyWidget()
proxy.setWidget(label)scene.addItem(proxy)view.rotate(-90) # 旋转视图view.fitInView(view.scene().sceneRect(), Qt.KeepAspectRatio)view.show()
app.exec_()