我是洛斯阿拉莫斯国家实验室的一名开发人员,我正在致力于将我们所有的软件的古老的Tkinter gui升级到Qt5。我想通过QML使这些GUI非常漂亮,并已经为其中一个程序编写了代码。我将用这个程序作为一个例子,我想提供数据的QtCharts从python。 我有一个单独的变量,它是一个python类型列表,我想在一个按钮单击事件上将其提供给QtCharts。请注意,这里是硬编码的真实数据作为示例。我的愿望是把这些数据(从一个列表中)以某种方式给行系列。 这是我的QML:
import QtQuick.Controls 2.5
import QtQuick.Controls.Material 2.3
import QtCharts 2.3
ApplicationWindow {
id: applicationWindow
visible: true
width: 720
height: 780
title: qsTr("Pomraning Driver")
Material.background: Material.color(Material.Grey, Material.Shade900)
GroupBox {
id: groupBox
width: 114
anchors.top: parent.top
anchors.topMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
Button {
id: button
objectName: "button"
x: 8
y: 0
width: 74
height: 48
text: qsTr("E_r")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button1
x: 8
y: 54
width: 74
height: 48
text: qsTr("dE_r/dr")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button2
x: 8
y: 108
width: 74
height: 48
text: qsTr("dE_r/dt")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button3
x: 8
y: 162
width: 74
height: 48
text: qsTr("T")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button4
x: 8
y: 216
width: 74
height: 48
text: qsTr("dT/dr")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button5
x: 8
y: 270
width: 74
height: 48
text: qsTr("dT/dt")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button6
x: 8
y: 324
width: 74
height: 48
text: qsTr("F")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button7
x: 8
y: 378
width: 74
height: 48
text: qsTr("M_d")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button8
x: 8
y: 432
width: 74
height: 48
text: qsTr("M_f")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button11
x: 8
y: 486
width: 74
height: 48
text: qsTr("D")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button12
x: 8
y: 540
width: 74
height: 48
text: qsTr("P")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button13
x: 8
y: 594
width: 74
height: 48
text: qsTr("E_m")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button14
x: 8
y: 648
width: 74
height: 48
text: qsTr("M_dep")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button15
x: 8
y: 702
width: 74
height: 48
text: qsTr("E_dep")
font.pointSize: 10
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
}
GroupBox {
id: groupBox2
anchors.right: parent.right
anchors.rightMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
anchors.left: parent.left
anchors.leftMargin: 114
anchors.bottom: parent.bottom
anchors.bottomMargin: 75
ChartView {
id: myChart
dropShadowEnabled: false
anchors.left: parent.left
anchors.leftMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
anchors.right: parent.right
anchors.rightMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
theme: ChartView.ChartThemeDark
antialiasing: true
backgroundColor: Material.color(Material.Grey, Material.Shade900)
LineSeries {
name: "Marshak Wave"
id: series
XYPoint { x: 0.0; y: -0.01282554019050467}
XYPoint { x: 0.01; y: -0.012917209897862346 }
XYPoint { x: 0.02; y: -0.013010527681317144 }
XYPoint { x: 0.03; y: -0.013105552631912468 }
XYPoint { x: 0.04; y: -0.01320234697625598 }
XYPoint { x: 0.05; y: -0.013301036371861025 }
XYPoint { x: 0.06; y: -0.013401651978143365 }
XYPoint { x: 0.07; y: -0.01350424830512767 }
XYPoint { x: 0.08; y: -0.01360890275027545 }
XYPoint { x: 0.09; y: -0.013715741772219603 }
XYPoint { x: 0.10; y: -0.013824852066157663}
XYPoint { x: 0.11; y: -0.013936285055210404 }
XYPoint { x: 0.12; y: -0.014050138500732967 }
XYPoint { x: 0.13; y: -0.014166542311302112}
XYPoint { x: 0.14; y: -0.014285652256035113 }
XYPoint { x: 0.15; y: -0.014407519430618555 }
XYPoint { x: 0.16; y: -0.0145322695282585 }
XYPoint { x: 0.17; y: -0.014660040313341397 }
XYPoint { x: 0.18; y: -0.0147910752750793 }
XYPoint { x: 0.19; y: -0.01492543012687811 }
XYPoint { x: 0.20; y: -0.015063269846073377 }
XYPoint { x: 0.21; y: -0.015204771543350504 }
XYPoint { x: 0.22; y: -0.015350220654983586 }
XYPoint { x: 0.23; y: -0.015499758561949212 }
XYPoint { x: 0.24; y: -0.015653583058938898 }
XYPoint { x: 0.25; y: -0.01581193395994599 }
XYPoint { x: 0.26; y: -0.015975145672289234 }
XYPoint { x: 0.27; y: -0.01614349302964807 }
XYPoint { x: 0.28; y: -0.016317224443693563 }
XYPoint { x: 0.29; y: -0.016496674698568532 }
XYPoint { x: 0.30; y: -0.016682257642044195 }
XYPoint { x: 0.31; y: -0.016874440233938682 }
XYPoint { x: 0.32; y: -0.017073559885397795 }
XYPoint { x: 0.33; y: -0.017280101755773845 }
XYPoint { x: 0.34; y: -0.017494613939520984 }
XYPoint { x: 0.35; y: -0.017717853994373766 }
XYPoint { x: 0.36; y: -0.017950320804753853 }
XYPoint { x: 0.37; y: -0.018192751131528576 }
XYPoint { x: 0.38; y: -0.018445969511917657 }
XYPoint { x: 0.39; y: -0.01871108985417959 }
XYPoint { x: 0.40; y: -0.018989030525813775 }
XYPoint { x: 0.41; y: -0.019280942692146814 }
XYPoint { x: 0.42; y: -0.019588180373485666 }
XYPoint { x: 0.43; y: -0.019912458907317358 }
XYPoint { x: 0.44; y: -0.020255544448877432 }
XYPoint { x: 0.45; y: -0.020619405414206676 }
XYPoint { x: 0.46; y: -0.021006468493468298 }
XYPoint { x: 0.47; y: -0.02141971417339604 }
XYPoint { x: 0.48; y: -0.021862680823132183 }
XYPoint { x: 0.49; y: -0.022339217802798166 }
XYPoint { x: 0.50; y: -0.02285425357940278 }
XYPoint { x: 0.51; y: -0.02341387707091308 }
XYPoint { x: 0.52; y: -0.024026033669786957 }
XYPoint { x: 0.53; y: -0.024699785875933484 }
XYPoint { x: 0.54; y: -0.02544728522966316 }
XYPoint { x: 0.55; y: -0.026284441002978654 }
XYPoint { x: 0.56; y: -0.027233342329850283 }
XYPoint { x: 0.57; y: -0.0283230628486692 }
XYPoint { x: 0.58; y: -0.029595720455507568 }
XYPoint { x: 0.59; y: -0.031114398637706826 }
XYPoint { x: 0.60; y: -0.03297993865573573 }
XYPoint { x: 0.61; y: -0.03536275846674127 }
XYPoint { x: 0.62; y: -0.0385855168210723 }
XYPoint { x: 0.63; y: -0.04336979005581715 }
XYPoint { x: 0.64; y: -0.05187120694787391 }
XYPoint { x: 0.65; y: -0.07778000112048876 }
}
}
}
GroupBox {
id: groupBox1
y: 704
height: 76
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 114
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
Button {
id: button9
y: 4
width: 136
height: 48
text: qsTr("x (cm)")
anchors.left: parent.left
anchors.leftMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button10
x: 142
y: 4
width: 136
height: 48
text: qsTr("t (sh)")
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button16
x: 304
y: 4
width: 136
height: 48
text: qsTr("Save Plot Data")
anchors.right: button17.left
anchors.rightMargin: 6
font.pointSize: 10
anchors.bottomMargin: 0
anchors.bottom: parent.bottom
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
Button {
id: button17
x: 446
y: 4
width: 136
height: 48
text: qsTr("Save Plot")
anchors.right: parent.right
anchors.rightMargin: 0
font.pointSize: 10
anchors.bottomMargin: 0
anchors.bottom: parent.bottom
Material.foreground: Material.color(Material.Grey, Material.Shade100)
Material.background: Material.color(Material.Grey, Material.Shade800)
}
}
}
问题来源StackOverflow 地址:/questions/59379854/how-to-get-lineseries-to-show-in-qt-charts-on-button-click
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。