45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
![]() |
from PyQt5.QtWidgets import QFrame, QWidget, QVBoxLayout
|
||
|
from PyQt5.QtGui import QPainter
|
||
|
from PyQt5.QtChart import QChart, QChartView
|
||
|
|
||
|
|
||
|
class YourClassName(QWidget):
|
||
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
|
||
|
self.plot_qchart = QChart()
|
||
|
self.plot_view = QChartView()
|
||
|
|
||
|
# 设置图表到视图
|
||
|
self.plot_view.setChart(self.plot_qchart)
|
||
|
|
||
|
# 开启抗锯齿
|
||
|
self.plot_view.setRenderHint(QPainter.Antialiasing)
|
||
|
|
||
|
# 设置矩形橡皮筋
|
||
|
self.plot_view.setRubberBand(QChartView.RectangleRubberBand)
|
||
|
|
||
|
# 移除外部边框
|
||
|
self.plot_view.setFrameShape(QFrame.NoFrame)
|
||
|
|
||
|
# 使用样式表进一步移除边框
|
||
|
self.plot_view.setStyleSheet("border: none;")
|
||
|
|
||
|
self.plot_qchart.setBackgroundRoundness(0)
|
||
|
self.plot_qchart.layout().setContentsMargins(0, 0, 0, 0)
|
||
|
|
||
|
|
||
|
# 将 QChartView 添加到布局中(如果需要)
|
||
|
layout = QVBoxLayout(self)
|
||
|
layout.addWidget(self.plot_view)
|
||
|
|
||
|
|
||
|
# 创建并显示窗口
|
||
|
if __name__ == "__main__":
|
||
|
from PyQt5.QtWidgets import QApplication
|
||
|
|
||
|
|
||
|
app = QApplication([])
|
||
|
window = YourClassName()
|
||
|
window.show()
|
||
|
app.exec_()
|