当前位置:网站首页>Qchartview overwrites the previous control when it is added in qgridlayout
Qchartview overwrites the previous control when it is added in qgridlayout
2022-07-19 14:34:00 【Beginner Xiaobai Lu】
problem
QChartView Add in QGridLayout The previous control is overwritten when in , Display only QChart
import sys
from random import uniform, random
from PySide2.QtCharts import QtCharts
from PySide2.QtCore import QPointF
from PySide2.QtGui import QPainter
from PySide2.QtWidgets import QWidget, QGridLayout, QApplication
class MainWidget(QWidget):
def __init__(self):
super(MainWidget, self).__init__()
self.main_layout = QGridLayout()
self.setLayout(self.main_layout)
widegt1 = QWidget()
widegt1.setStyleSheet("background-color: red")
widget2 = QWidget()
widget2.setStyleSheet("background-color: red")
self.main_layout.addWidget(widegt1, 0, 0, 3, 2)
self.main_layout.addWidget(widget2, 0, 2, 2, 1)
self.list_count = 3
self.value_max = 10
self.value_count = 7
self.data_table = self.generate_random_data(self.list_count,
self.value_max, self.value_count)
chart_view = QtCharts.QChartView(self.createSplineChart())
chart_view.setRenderHint(QPainter.Antialiasing)
self.main_layout.addWidget(chart_view, 2, 2, 1, 1)
# self.main_layout.setColumnStretch(0, 1)
# self.main_layout.setColumnStretch(1, 1)
# self.main_layout.setColumnStretch(2, 1)
# self.main_layout.setRowStretch(0, 1)
# self.main_layout.setRowStretch(1, 1)
# self.main_layout.setRowStretch(2, 1)
def createSplineChart(self):
chart = QtCharts.QChart()
chart.setTitle("Spline chart")
name = "Series "
for i, lst in enumerate(self.data_table):
series = QtCharts.QSplineSeries(chart)
for data in lst:
series.append(data[0])
series.setName("{}{}".format(name, i))
chart.addSeries(series)
chart.createDefaultAxes()
chart.axisX().setRange(0, self.value_max)
chart.axisY().setRange(0, self.value_count)
# Add space to label to add space between labels and axis
chart.axisY().setLabelFormat("%.1f ")
return chart
def generate_random_data(self, list_count, value_max, value_count):
data_table = []
for i in range(list_count):
data_list = []
y_value = 0
for j in range(value_count):
constant = value_max / float(value_count)
y_value += uniform(0, constant)
x_value = (j + random()) * constant
value = QPointF(x_value, y_value)
label = "Slice {}: {}".format(i, j)
data_list.append((value, label))
data_table.append(data_list)
return data_table
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWidget()
# available_geometry = app.desktop().availableGeometry(window)
# size = available_geometry.height() * 0.75
# window.resize(size, size * 0.8)
window.show()
sys.exit(app.exec_())

terms of settlement
Set the proportion of each column and row
Add the following code :
self.main_layout.setColumnStretch(0, 1)
self.main_layout.setColumnStretch(1, 1)
self.main_layout.setColumnStretch(2, 1)
self.main_layout.setRowStretch(0, 1)
self.main_layout.setRowStretch(1, 1)
self.main_layout.setRowStretch(2, 1)

边栏推荐
- C - usage of this
- Okaleido or get out of the NFT siege, are you optimistic about it?
- C # read and write text and generate QR code
- 【MQTT从入门到提高系列 | 06】MQTT3.1.1之SUBSCRIBE订阅工作流
- js刷题练习---牛客网
- Opencv template
- 4某公司在6个城市c1,c2,c3…c6中有分公司,已知城市ci到cj(I,j=1,2,3,…6)的联通情况下及费用的大小列于以下带权邻接矩阵中C中
- P8346 the clearest air and sea [undirected graph topology]
- Si446 usage record (III): match function
- 欧奈尔的RPS曲线的编制方法(陶博士原创)
猜你喜欢

96. Different binary search trees

Huawei wireless device configuration intelligent roaming

Huawei Technologies:Jonatan Krolikowski | 从设计到部署零接触深度强化学习WLANs
![Luo Gu: p3092 [usaco13nov]no change G](/img/b9/8cacd3d4ae1cf014654e0204cb3a62.png)
Luo Gu: p3092 [usaco13nov]no change G

Redis source code and design analysis -- 3 Dictionaries

负载均衡有哪几种实现方式?

Unveil the mystery of service grid istio service mesh

Event preview | Apache Doris x Apache seatunnel joint meetup to start registration!

Huawei wireless device configuration dynamic load balancing

The manual is not complete. How to manually dig out the monitoring information of tongweb?
随机推荐
unity 字幕滚动
96. Different binary search trees
After 2000, he was hired as a special associate researcher of Nanjing University. He went to primary school at the age of 4 and was admitted to Nanjing University at the age of 14!
Redis source code and design analysis -- 4 Jump table
05--- antireflective film
Code runner for vs code, with more than 40million downloads! Support more than 50 languages
4某公司在6个城市c1,c2,c3…c6中有分公司,已知城市ci到cj(I,j=1,2,3,…6)的联通情况下及费用的大小列于以下带权邻接矩阵中C中
unity 实现UI-背包装备拖拽功能
Redis源码与设计剖析 -- 1.简单动态字符串
SCM software timer v2.0
ping 命令还能这么玩?
华为无线设备配置智能漫游
Logu: p4516 [jsoi2018] stealth action (tree DP, tree grouping knapsack statistical scheme number)
Prefix equality [DP | hash]
Tree and bipartite graph [thinking]
Optimizer of pytoch framework optimizer
Luo Gu: p3092 [usaco13nov]no change G
Pyside2嵌入Matplotlib的绘图
[Flink] Flink will report an error if it fails to set checkpoints once. Setlerablecheckpointfailurenumber does not work
Silent AI: how does shengteng AI solve the problem of sign language learning with large models?