pyside6學習專欄(九):在PySide6中使用PySide6.QtCharts繪制6種不同的圖表的示例代碼

PySide6的QtCharts類支持繪制各種型狀的圖表,如面積區域圖、餅狀圖、折線圖、直方圖、線條曲線圖、離散點圖等,下面的代碼是采用示例數據繪制這6種圖表的示例代碼,并可實現動畫顯示效果,實際使用時參照代碼中示例數據的格式將實際數據替換即可實現圖表格式的顯示

本代碼是將PySide6官方示例代碼增加中文注釋,同時將代碼中隨機產生的數據改為更直觀的示例列表數據值,以更直觀的了解數據同圖表顯示的關系。

對應python代碼如下:

# PySide6.QtCharts的6種方式顯示圖表的示例程序

from __future__ import annotations

?

import sys

from PySide6.QtCore import QPointF, Qt

from PySide6.QtGui import QColor, QPainter, QPalette

from PySide6.QtWidgets import (QApplication, QMainWindow, QSizePolicy,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?QWidget)

from PySide6.QtCharts import (QAreaSeries, QBarSet, QChart, QChartView,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? QLineSeries, QPieSeries, QScatterSeries,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? QSplineSeries, QStackedBarSeries)

?

from ui_themewidget import Ui_ThemeWidgetForm as ui ? ?

?

from random import random, uniform

?

#示例主窗口

class ThemeWidget(QWidget):

? ? def __init__(self, parent):

? ? ? ? QWidget.__init__(self, parent)

?

? ? ? ? self.charts = [] ? #定義本示例要用的圖表:共下面6種類型

?

? ? ? ? self.ui = ui() ? ?#為ui設置器設計的窗體實例化一對象,要調用此模塊中的控件對象或繼續初始化窗體布局

? ? ? ?

? ? ? ? self.ui.setupUi(self) ? ? ? ?#初始化主窗口自身界面(使用設計器編制的窗口themewidget.ui編繹成窗口模塊文件ui_themewidget.py.在終端命令行中輸入: ?PySide6-uic 'themewidget.ui' ?-o 'ui_themewidget.py' )

? ? ? ? self.populate_themebox() ? ? #初始化顯示顏色組合框

? ? ? ? self.populate_animationbox() #初始化動畫選項組合框

? ? ? ? self.populate_legendbox() ? ?#初始化圖標位置組合框

? ? ? ?

? ? ? ? # 面積區域圖表顯示視圖

? ? ? ? chart_view = QChartView(self.create_areachart())

? ? ? ? self.ui.gridLayout.addWidget(chart_view, 1, 0) ? #繼續完成UI設計器中沒有完成的界面初始化工作:網格布局依次加入6個view

? ? ? ? self.charts.append(chart_view)

?

? ? ? ? #餅狀圖顯示視圖

? ? ? ? chart_view = QChartView(self.create_pie_chart())

? ? ? ? chart_view.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)

? ? ? ? self.ui.gridLayout.addWidget(chart_view, 1, 1)

? ? ? ? self.charts.append(chart_view)

?

? ? ? ? #折線圖顯示視圖

? ? ? ? chart_view = QChartView(self.create_line_chart())

? ? ? ? self.ui.gridLayout.addWidget(chart_view, 1, 2)

? ? ? ? self.charts.append(chart_view)

?

? ? ? ? #直方圖顯示視圖

? ? ? ? chart_view = QChartView(self.create_bar_chart())

? ? ? ? self.ui.gridLayout.addWidget(chart_view, 2, 0)

? ? ? ? self.charts.append(chart_view)

?

? ? ? ? #樣條直線圖顯示視圖

? ? ? ? chart_view = QChartView(self.create_spline_chart())

? ? ? ? self.ui.gridLayout.addWidget(chart_view, 2, 1)

? ? ? ? self.charts.append(chart_view)

?

? ? ? ? #離散點圖顯示視圖

? ? ? ? chart_view = QChartView(self.create_scatterchart())

? ? ? ? self.ui.gridLayout.addWidget(chart_view, 2, 2)

? ? ? ? self.charts.append(chart_view)

?

? ? ? ? #設置默認支持抗鋸齒

? ? ? ? self.ui.antialiasCheckBox.setChecked(True)

?

? ? ? ? #設置默認顯示顏色

? ? ? ? pal = qApp.palette()

? ? ? ? pal.setColor(QPalette.Window, QColor(0xf0f0f0))

? ? ? ? pal.setColor(QPalette.WindowText, QColor(0x404044))

? ? ? ? qApp.setPalette(pal)

?

? ? ? ? self.update_ui() ? #刷新一次顯示

? ?

? ? #初始化顏色類型選項組合框

? ? def populate_themebox(self):

? ? ? ? theme = self.ui.themeComboBox

? ? ? ? theme.addItem("亮白", QChart.ChartThemeLight)

? ? ? ? theme.addItem("天藍色", QChart.ChartThemeBlueCerulean)

? ? ? ? theme.addItem("暗色調", QChart.ChartThemeDark)

? ? ? ? theme.addItem("棕沙色", QChart.ChartThemeBrownSand)

? ? ? ? theme.addItem("藍NCS", QChart.ChartThemeBlueNcs)

? ? ? ? theme.addItem("高對比", QChart.ChartThemeHighContrast)

? ? ? ? theme.addItem("藍Icy", QChart.ChartThemeBlueIcy)

? ? ? ? theme.addItem("Qt", QChart.ChartThemeQt)

? ? #初始化動畫類型選項組合框

? ? def populate_animationbox(self):

? ? ? ? animated = self.ui.animatedComboBox

? ? ? ? animated.addItem("無動畫", QChart.NoAnimation)

? ? ? ? animated.addItem("沿網格軸動畫", QChart.GridAxisAnimations)

? ? ? ? animated.addItem("連續動畫", QChart.SeriesAnimations)

? ? ? ? animated.addItem("所有動畫", QChart.AllAnimations)

? ? #初始化圖例顯示位置選項組合框

? ? def populate_legendbox(self):

? ? ? ? legend = self.ui.legendComboBox

? ? ? ? legend.addItem("無圖例", 0)

? ? ? ? legend.addItem("圖例在上", Qt.AlignTop)

? ? ? ? legend.addItem("圖例在下", Qt.AlignBottom)

? ? ? ? legend.addItem("圖例在左", Qt.AlignLeft)

? ? ? ? legend.addItem("圖例在右", Qt.AlignRight)

?

? ? #1.創建面積區域類型圖表

? ? def create_areachart(self):

? ? ? ? chart = QChart()

? ? ? ? chart.setTitle("面積區域圖")

? ? ? ? #下面定義面積區域的三條線上的點坐標示例數據

? ? ? ? lstDatas1=[[0.0,1.1],[2.0,1.5],[3.0,1.8],[4.0,2.1],[5.0,2.6],[6.0,2.9]]

? ? ? ? lstDatas2=[[0.0,3.1],[2.0,3.5],[3.0,3.5],[4.0,4.1],[5.0,4.6],[6.0,4.9]]

? ? ? ? lstDatas3=[[0.0,6.1],[2.0,6.5],[3.0,6.8],[4.0,8.5],[5.0,8.9],[6.0,9.3]]

? ? ? ? lstDatas=[]

? ? ? ? lstDatas.append(lstDatas1)

? ? ? ? lstDatas.append(lstDatas2)

? ? ? ? lstDatas.append(lstDatas3)

? ? ? ? count=len(lstDatas1)

? ? ? ? #底層線位置

? ? ? ? lower_series = None

? ? ? ? name = "A" ? ?#設置圖標名前綴

? ? ? ? id=0

? ? ? ? for oneDatas in lstDatas:

? ? ? ? ? ? upper_series = QLineSeries(chart) ? ? ? ?#上層線位置

? ? ? ? ? ? for onePoint in oneDatas:

? ? ? ? ? ? ? ? x=onePoint[0]

? ? ? ? ? ? ? ? y=onePoint[1]

? ? ? ? ? ? ? ? upper_series.append(QPointF(x,y))

? ? ? ? ? ? id+=1

? ? ? ? ? ? area = QAreaSeries(upper_series, lower_series) ?

? ? ? ? ? ? area.setName(f"{name}{id}")

? ? ? ? ? ? chart.addSeries(area)

? ? ? ? ? ? lower_series = upper_series ? ? ? ? ? ? ? ? ? ? ? ? ? #下一個區的的上層線變成下一個區域的底層線

? ? ? ?

? ? ? ? chart.createDefaultAxes()

? ? ? ? axis_x = chart.axes(Qt.Orientation.Horizontal)[0]

? ? ? ? axis_x.setRange(0, count-1) ? ?#設置X軸標區間

? ? ? ? axis_y = chart.axes(Qt.Vertical)[0]

? ? ? ? axis_y.setRange(0,10) ? ? ? ? ?#設置X軸標區間

?

? ? ? ? #增加軸標在軸線外側

? ? ? ? axis_y.setLabelFormat("%.1f ?")

?

? ? ? ? return chart

? ?

? ? #2.創建餅狀圖圖表

? ? def create_pie_chart(self):

? ? ? ? chart = QChart()

? ? ? ? chart.setTitle("餅狀圖")

? ? ? ? series = QPieSeries(chart)

? ? ? ? #下面餅狀圖中各區域的示例值

? ? ? ? lstDatas=[1.0,2.0,3.0,4.0,5.0,6.0,7.0]

? ? ? ? count=len(lstDatas)

? ? ? ? id=0

? ? ? ? for oneBarValue in ?lstDatas:

? ? ? ? ? ? barStr=f'餅:{id+1}'

? ? ? ? ? ? slc=series.append(barStr,oneBarValue)

? ? ? ? ? ? if(id==4): ? #如當前為id=4號的餅數據時,將此餅狀區域(序號4+1)單獨提出來分離開顯示

? ? ? ? ? ? ? ? slc.setLabelVisible()

? ? ? ? ? ? ? ? slc.setExploded()

? ? ? ? ? ? ? ? slc.setExplodeDistanceFactor(0.5)

? ? ? ? ? ? id+=1

?

? ? ? ? series.setPieSize(0.5) ? ?#設置餅顯示尺寸相對視中的占比

? ? ? ? chart.addSeries(series)

?

? ? ? ? return chart

? ?

? ? ?#3.創建折線圖圖表

? ? def create_line_chart(self):

? ? ? ? chart = QChart()

? ? ? ? chart.setTitle("線性圖")

? ? ? ? #下面定義三組每條折線上的點坐標示例數據

? ? ? ? lstDatas1=[[0.0,1.1],[2.0,1.5],[3.0,1.8],[4.0,2.1],[5.0,2.6],[6.0,2.9]]

? ? ? ? lstDatas2=[[0.0,3.1],[2.0,3.5],[3.0,3.5],[4.0,4.1],[5.0,4.6],[8.0,4.9]]

? ? ? ? lstDatas3=[[0.0,6.1],[2.0,6.5],[3.0,6.8],[4.0,8.5],[5.0,8.9],[10.0,9.3]]

? ? ? ? lstDatas=[]

? ? ? ? lstDatas.append(lstDatas1)

? ? ? ? lstDatas.append(lstDatas2)

? ? ? ? lstDatas.append(lstDatas3)

? ? ? ? name = "C" ? #設置圖標名前綴

?

? ? ? ? id=0

? ? ? ? for oneDatas in lstDatas:

? ? ? ? ? ? series = QLineSeries(chart)

? ? ? ? ? ? for onePoint in oneDatas:

? ? ? ? ? ? ? ? series.append(QPointF(onePoint[0],onePoint[1])) ? ? ? ? ? ?#得到數據中的點值要轉換為QPointF

? ? ? ? ? ? series.setName(f"{name}{id}") ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#為每條線(共3條)設置圖標名稱

? ? ? ? ? ? chart.addSeries(series)

? ? ? ? ? ? id+=1

?

? ? ? ? chart.createDefaultAxes()

? ? ? ? axis_x = chart.axes(Qt.Orientation.Horizontal)[0]

? ? ? ? axis_x.setRange(0, 10) ? ? ? ? ? ? ? ? #設置X軸標區間

? ? ? ? axis_y = chart.axes(Qt.Vertical)[0]

? ? ? ? axis_y.setRange(0, 10) ? ? ? ? ? ? ? ? #設置y軸標區間

? ? ? ? #增加軸標在軸線外側

? ? ? ? axis_y.setLabelFormat("%.1f ?")

?

? ? ? ? return chart

? ?

? ? #4.創建直方圖類型圖表

? ? def create_bar_chart(self):

? ? ? ? chart = QChart()

? ? ? ? chart.setTitle("直方圖")

? ? ? ? #下面定義三組數據在每個矩形上的高度示例數據

? ? ? ? lstDatas1=[1.0,2.0,3.0,4.0,5.0,6.0,7.0]

? ? ? ? lstDatas2=[1.0,3.0,5.0,7.0,2.0,4.0,6.0]

? ? ? ? lstDatas3=[7.0,6.0,5.0,4.0,3.0,3.0,1.0]

? ? ? ? lstDatas=[]

? ? ? ? lstDatas.append(lstDatas1)

? ? ? ? lstDatas.append(lstDatas2)

? ? ? ? lstDatas.append(lstDatas3)

?

? ? ? ? series = QStackedBarSeries(chart)

? ? ? ? id=0

? ? ? ? for oneDatas in lstDatas: ? ? ? ? ? ? ? ? ? #得到3組數據中的每一組數據

? ? ? ? ? ? barset = QBarSet(f"D{id}") ? ? ? ? ? ? ?#為每組數據設置對象及對應圖標名

? ? ? ? ? ? for oneRectY in oneDatas: ? ? ? ? ? ? ? #得到每組數據中的Y值

? ? ? ? ? ? ? ? barset.append(oneRectY)

? ? ? ? ? ? series.append(barset) ? ? ? ? ? ? ? ? ? #共創建7項直方圖(X向),每組直方圖有3個矩形區,如X軸第1列矩形的高分別為:lstDatas1[0],中間為lstDatas2[0],上部矩形為lstDatas3[0]

? ? ? ? ? ? id+=1

? ? ? ? chart.addSeries(series)

? ? ? ? chart.createDefaultAxes()

? ? ? ? axis_y = chart.axes(Qt.Vertical)[0]

? ? ? ? axis_y.setRange(0, 30) ? ? ? ? ? ? ? ? ?#設置Y軸網格最大高度,不用此句時,為三組數據最大值合

? ? ? ? axis_y.setLabelFormat("%.2f ?") ? ? ? ? #Y軸標顯示格式

? ? ? ? return chart

? ?

? ? #5.創建樣條曲線類型圖表

? ? def create_spline_chart(self):

? ? ? ? chart = QChart()

? ? ? ? chart.setTitle("樣條曲線圖")

? ? ? ? name = "E" ? ?#設置圖標名前綴

? ? ? ? #下面定義三組每條樣條曲線上的點坐標示例數據

? ? ? ? lstDatas1=[[0.0,1.1],[2.0,1.5],[3.0,1.8],[4.0,2.1],[5.0,2.6],[6.0,2.9]]

? ? ? ? lstDatas2=[[0.0,3.1],[2.0,3.5],[3.0,3.5],[4.0,4.1],[5.0,4.6],[8.0,4.9]]

? ? ? ? lstDatas3=[[0.0,6.1],[2.0,6.5],[3.0,6.8],[4.0,8.5],[5.0,8.9],[10.0,9.3]]

? ? ? ? lstDatas=[]

? ? ? ? lstDatas.append(lstDatas1)

? ? ? ? lstDatas.append(lstDatas2)

? ? ? ? lstDatas.append(lstDatas3)

? ? ? ? id=0

? ? ? ? for oneDatas in lstDatas:

? ? ? ? ? ? series = QSplineSeries(chart)

? ? ? ? ? ? for onePoint in oneDatas:

? ? ? ? ? ? ? ? series.append(QPointF(onePoint[0],onePoint[1])) ? ? ? ? ? ?#得到數據中的點值要轉換為QPointF

? ? ? ? ? ? series.setName(f"{name}{id}") ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#為每條線(共3條)設置圖標名稱

? ? ? ? ? ? chart.addSeries(series)

? ? ? ? ? ? id+=1

?

? ? ? ? chart.createDefaultAxes()

? ? ? ? axis_x = chart.axes(Qt.Orientation.Horizontal)[0]

? ? ? ? axis_x.setRange(0,10) ? ? ? ? ? ? ? ? ? ?#設置X軸標區間

? ? ? ? axis_y = chart.axes(Qt.Vertical)[0]

? ? ? ? axis_y.setRange(0, 10) ? ? ? ? ? ? ? ? ? #設置X軸標區間

? ? ? ? axis_y.setLabelFormat("%.1f ?")

? ? ? ? return chart

? ?

? ? #6.創建離散點類型圖表

? ? def create_scatterchart(self):

? ? ? ? chart = QChart()

? ? ? ? chart.setTitle("離散點圖")

? ? ? ? name = "F"

? ? ? ? #下面定義三組離散點坐標示例數據:共21個點

? ? ? ? lstDatas1=[[0.2,1.1],[2.0,1.5],[3.0,1.8],[4.0,2.1],[5.0,2.6],[6.0,2.9]]

? ? ? ? lstDatas2=[[0.4,3.1],[2.0,3.5],[3.0,3.5],[4.0,4.1],[5.0,4.6],[8.0,4.9]]

? ? ? ? lstDatas3=[[0.5,6.1],[2.0,6.5],[3.0,6.8],[4.0,8.5],[5.0,8.9],[9.8,9.3]]

? ? ? ? lstDatas=[]

? ? ? ? lstDatas.append(lstDatas1)

? ? ? ? lstDatas.append(lstDatas2)

? ? ? ? lstDatas.append(lstDatas3)

? ? ? ? id=0

? ? ? ? for oneDatas in lstDatas:

? ? ? ? ? ? series = QScatterSeries(chart)

? ? ? ? ? ? for onePoint in oneDatas:

? ? ? ? ? ? ? ? series.append(QPointF(onePoint[0],onePoint[1])) ? ? ? ? ? ?#得到數據中的點值要轉換為QPointF

? ? ? ? ? ? series.setName(f"{name}{id}") ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#為每條線(共3條)設置圖標名稱

? ? ? ? ? ? chart.addSeries(series)

? ? ? ? ? ? id+=1

?

? ? ? ? chart.createDefaultAxes()

? ? ? ? axis_x = chart.axes(Qt.Orientation.Horizontal)[0]

? ? ? ? axis_x.setRange(0,10) ? ? ? ? ?#設置X軸標區間(最大值為數據中的X最大值)

? ? ? ? axis_y = chart.axes(Qt.Vertical)[0]

? ? ? ? axis_y.setRange(0, 10) ? ? ? ? #設置y軸標區間 (最大值為數據中的y最大值)

? ? ? ? axis_y.setLabelFormat("%.1f ?")

?

? ? ? ? return chart

? ?

? ? #按當前的設置選項更新顯示視圖:組合框選項發生變化時均會自動調用此函數,本例無需定義對應的信號槽函數?

? ? def update_ui(self):

? ? ? ? def set_colors(window_color, text_color):

? ? ? ? ? ? pal = self.window().palette()

? ? ? ? ? ? pal.setColor(QPalette.Window, window_color)

? ? ? ? ? ? pal.setColor(QPalette.WindowText, text_color)

? ? ? ? ? ? self.window().setPalette(pal)

?

? ? ? ? idx = self.ui.themeComboBox.currentIndex()

? ? ? ? theme = self.ui.themeComboBox.itemData(idx)

?

? ? ? ? if len(self.charts):

? ? ? ? ? ? chart_theme = self.charts[0].chart().theme()

? ? ? ? ? ? if chart_theme != theme:

? ? ? ? ? ? ? ? for chart_view in self.charts:

? ? ? ? ? ? ? ? ? ? chart_view.chart().setTheme(theme)

?

? ? ? ? ? ? ? ? #根據選擇的類型更新顏色面板

? ? ? ? ? ? ? ? if theme == QChart.ChartThemeLight:

? ? ? ? ? ? ? ? ? ? set_colors(QColor(0xf0f0f0), QColor(0x404044))

? ? ? ? ? ? ? ? elif theme == QChart.ChartThemeDark:

? ? ? ? ? ? ? ? ? ? set_colors(QColor(0x121218), QColor(0xd6d6d6))

? ? ? ? ? ? ? ? elif theme == QChart.ChartThemeBlueCerulean:

? ? ? ? ? ? ? ? ? ? set_colors(QColor(0x40434a), QColor(0xd6d6d6))

? ? ? ? ? ? ? ? elif theme == QChart.ChartThemeBrownSand:

? ? ? ? ? ? ? ? ? ? set_colors(QColor(0x9e8965), QColor(0x404044))

? ? ? ? ? ? ? ? elif theme == QChart.ChartThemeBlueNcs:

? ? ? ? ? ? ? ? ? ? set_colors(QColor(0x018bba), QColor(0x404044))

? ? ? ? ? ? ? ? elif theme == QChart.ChartThemeHighContrast:

? ? ? ? ? ? ? ? ? ? set_colors(QColor(0xffab03), QColor(0x181818))

? ? ? ? ? ? ? ? elif theme == QChart.ChartThemeBlueIcy:

? ? ? ? ? ? ? ? ? ? set_colors(QColor(0xcee7f0), QColor(0x404044))

? ? ? ? ? ? ? ? else:

? ? ? ? ? ? ? ? ? ? set_colors(QColor(0xf0f0f0), QColor(0x404044))

?

? ? ? ? # 更新抗鋸齒顯示

? ? ? ? checked = self.ui.antialiasCheckBox.isChecked()

? ? ? ? for chart in self.charts:

? ? ? ? ? ? chart.setRenderHint(QPainter.RenderHint.Antialiasing, checked)

?

? ? ? ? #更新動畫顯示

? ? ? ? idx = self.ui.animatedComboBox.currentIndex()

? ? ? ? options = self.ui.animatedComboBox.itemData(idx)

?

? ? ? ? if len(self.charts):

? ? ? ? ? ? animation_options = self.charts[0].chart().animationOptions()

? ? ? ? ? ? if animation_options != options:

? ? ? ? ? ? ? ? for chart_view in self.charts:

? ? ? ? ? ? ? ? ? ? chart_view.chart().setAnimationOptions(options)

?

? ? ? ? # 更新圖例顯示位置

? ? ? ? idx = self.ui.legendComboBox.currentIndex()

? ? ? ? alignment = self.ui.legendComboBox.itemData(idx)

?

? ? ? ? if not alignment:

? ? ? ? ? ? for chart_view in self.charts:

? ? ? ? ? ? ? ? chart_view.chart().legend().hide()

? ? ? ? else:

? ? ? ? ? ? for chart_view in self.charts:

? ? ? ? ? ? ? ? alignment_name = Qt.AlignTop

? ? ? ? ? ? ? ? if alignment == 32:

? ? ? ? ? ? ? ? ? ? alignment_name = Qt.AlignTop

? ? ? ? ? ? ? ? elif alignment == 64:

? ? ? ? ? ? ? ? ? ? alignment_name = Qt.AlignBottom

? ? ? ? ? ? ? ? elif alignment == 1:

? ? ? ? ? ? ? ? ? ? alignment_name = Qt.AlignLeft

? ? ? ? ? ? ? ? elif alignment == 2:

? ? ? ? ? ? ? ? ? ? alignment_name = Qt.AlignRight

? ? ? ? ? ? ? ? chart_view.chart().legend().setAlignment(alignment_name)

? ? ? ? ? ? ? ? chart_view.chart().legend().show()

?

#程序入口

if __name__ == "__main__":

? ? app = QApplication(sys.argv)

? ? window = QMainWindow()

? ? widget = ThemeWidget(None)

? ? window.setCentralWidget(widget)

? ? available_geometry = window.screen().availableGeometry()

? ? size = available_geometry.height() * 1.0

? ? window.setFixedSize(size, size *0.85)

? ? window.show()

? ? window.setWindowTitle('PySide6.QtCharts的6種方式顯示圖表')

? ?

? ? sys.exit(app.exec())

下面是UI設計器的界面編繹后的ui_themewidget.py模塊代碼,此代碼文件同上面主模塊文件放在一個目錄即可

# -*- coding: utf-8 -*-################################################################################
## Form generated from reading UI file 'themewidget.ui'
##
## Created by: Qt User Interface Compiler version 6.8.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,QMetaObject, QObject, QPoint, QRect,QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,QFont, QFontDatabase, QGradient, QIcon,QImage, QKeySequence, QLinearGradient, QPainter,QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QCheckBox, QComboBox, QGridLayout,QHBoxLayout, QLabel, QSizePolicy, QSpacerItem,QWidget)class Ui_ThemeWidgetForm(object):def setupUi(self, ThemeWidgetForm):if not ThemeWidgetForm.objectName():ThemeWidgetForm.setObjectName(u"ThemeWidgetForm")ThemeWidgetForm.setWindowModality(Qt.WindowModality.WindowModal)ThemeWidgetForm.resize(1200, 900)self.gridLayout = QGridLayout(ThemeWidgetForm)self.gridLayout.setObjectName(u"gridLayout")self.horizontalLayout = QHBoxLayout()self.horizontalLayout.setObjectName(u"horizontalLayout")self.themeLabel = QLabel(ThemeWidgetForm)self.themeLabel.setObjectName(u"themeLabel")self.horizontalLayout.addWidget(self.themeLabel)self.themeComboBox = QComboBox(ThemeWidgetForm)self.themeComboBox.setObjectName(u"themeComboBox")self.horizontalLayout.addWidget(self.themeComboBox)self.animatedLabel = QLabel(ThemeWidgetForm)self.animatedLabel.setObjectName(u"animatedLabel")self.horizontalLayout.addWidget(self.animatedLabel)self.animatedComboBox = QComboBox(ThemeWidgetForm)self.animatedComboBox.setObjectName(u"animatedComboBox")self.horizontalLayout.addWidget(self.animatedComboBox)self.legendLabel = QLabel(ThemeWidgetForm)self.legendLabel.setObjectName(u"legendLabel")self.horizontalLayout.addWidget(self.legendLabel)self.legendComboBox = QComboBox(ThemeWidgetForm)self.legendComboBox.setObjectName(u"legendComboBox")self.horizontalLayout.addWidget(self.legendComboBox)self.antialiasCheckBox = QCheckBox(ThemeWidgetForm)self.antialiasCheckBox.setObjectName(u"antialiasCheckBox")self.antialiasCheckBox.setChecked(False)self.horizontalLayout.addWidget(self.antialiasCheckBox)self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)self.horizontalLayout.addItem(self.horizontalSpacer)self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 3)self.retranslateUi(ThemeWidgetForm)self.themeComboBox.currentIndexChanged.connect(ThemeWidgetForm.update_ui)self.antialiasCheckBox.toggled.connect(ThemeWidgetForm.update_ui)self.legendComboBox.currentIndexChanged.connect(ThemeWidgetForm.update_ui)self.animatedComboBox.currentIndexChanged.connect(ThemeWidgetForm.update_ui)QMetaObject.connectSlotsByName(ThemeWidgetForm)# setupUidef retranslateUi(self, ThemeWidgetForm):self.themeLabel.setText(QCoreApplication.translate("ThemeWidgetForm", u"\u8272\u8c03:", None))self.animatedLabel.setText(QCoreApplication.translate("ThemeWidgetForm", u"\u56fe\u4f8b:", None))self.legendLabel.setText(QCoreApplication.translate("ThemeWidgetForm", u"\u56fe\u4f8b:", None))self.antialiasCheckBox.setText(QCoreApplication.translate("ThemeWidgetForm", u"\u6297\u952f\u9f7f", None))pass# retranslateUi

UI文件“themewidget.ui”腳本如下,復制到一文本文件中另存為themewidget.ui,即可用UI設計器打開此界面文件

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>ThemeWidgetForm</class><widget class="QWidget" name="ThemeWidgetForm"><property name="windowModality"><enum>Qt::WindowModality::WindowModal</enum></property><property name="geometry"><rect><x>0</x><y>0</y><width>1200</width><height>900</height></rect></property><layout class="QGridLayout" name="gridLayout"><item row="0" column="0" colspan="3"><layout class="QHBoxLayout" name="horizontalLayout"><item><widget class="QLabel" name="themeLabel"><property name="text"><string>色調:</string></property></widget></item><item><widget class="QComboBox" name="themeComboBox"/></item><item><widget class="QLabel" name="animatedLabel"><property name="text"><string>圖例:</string></property></widget></item><item><widget class="QComboBox" name="animatedComboBox"/></item><item><widget class="QLabel" name="legendLabel"><property name="text"><string>圖例:</string></property></widget></item><item><widget class="QComboBox" name="legendComboBox"/></item><item><widget class="QCheckBox" name="antialiasCheckBox"><property name="text"><string>抗鋸齒</string></property><property name="checked"><bool>false</bool></property></widget></item><item><spacer name="horizontalSpacer"><property name="orientation"><enum>Qt::Orientation::Horizontal</enum></property><property name="sizeHint" stdset="0"><size><width>40</width><height>20</height></size></property></spacer></item></layout></item></layout></widget><resources/><connections><connection><sender>themeComboBox</sender><signal>currentIndexChanged(int)</signal><receiver>ThemeWidgetForm</receiver><slot>update_ui()</slot><hints><hint type="sourcelabel"><x>20</x><y>20</y></hint><hint type="destinationlabel"><x>20</x><y>20</y></hint></hints></connection><connection><sender>antialiasCheckBox</sender><signal>toggled(bool)</signal><receiver>ThemeWidgetForm</receiver><slot>update_ui()</slot><hints><hint type="sourcelabel"><x>20</x><y>20</y></hint><hint type="destinationlabel"><x>20</x><y>20</y></hint></hints></connection><connection><sender>legendComboBox</sender><signal>currentIndexChanged(int)</signal><receiver>ThemeWidgetForm</receiver><slot>update_ui()</slot><hints><hint type="sourcelabel"><x>20</x><y>20</y></hint><hint type="destinationlabel"><x>20</x><y>20</y></hint></hints></connection><connection><sender>animatedComboBox</sender><signal>currentIndexChanged(int)</signal><receiver>ThemeWidgetForm</receiver><slot>update_ui()</slot><hints><hint type="sourcelabel"><x>20</x><y>20</y></hint><hint type="destinationlabel"><x>20</x><y>20</y></hint></hints></connection></connections><slots><slot>update_ui()</slot></slots>
</ui>

?

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/897099.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/897099.shtml
英文地址,請注明出處:http://en.pswp.cn/news/897099.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《今日AI-人工智能-編程日報》

1. 字節跳動發布AI編程工具Trae國內版 發布背景&#xff1a;字節跳動于2025年3月3日正式推出國內版AI編程工具Trae&#xff0c;這是國內首個AI原生集成開發環境&#xff08;AI IDE&#xff09;&#xff0c;旨在提升開發者的編程效率與智能化體驗。 核心功能&#xff1a; 搭載d…

doris: MySQL

Doris JDBC Catalog 支持通過標準 JDBC 接口連接 MySQL 數據庫。本文檔介紹如何配置 MySQL 數據庫連接。 使用須知? 要連接到 MySQL 數據庫&#xff0c;您需要 MySQL 5.7, 8.0 或更高版本 MySQL 數據庫的 JDBC 驅動程序&#xff0c;您可以從 Maven 倉庫下載最新或指定版本的…

【LangChain】存儲與管理對話歷史

0. 代碼演示 from langchain_community.chat_message_histories import SQLChatMessageHistorydef get_session_history(session_id):# 通過 session_id 區分對話歷史&#xff0c;并存儲在 sqlite 數據庫中return SQLChatMessageHistory(session_id, "sqlite:///memory.d…

從0開始的操作系統手搓教程21:進程子系統的一個核心功能——簡單的進程切換

目錄 具體說說我們的簡單RR調度 處理時鐘中斷處理函數 調度器 schedule switch_to 我們下面&#xff0c;就要開始真正的進程切換了。在那之前&#xff0c;筆者想要說的是——我們實現的進程切換簡單的無法再簡單了——也就是實現一個超級簡單的輪詢調度器。 每一個進程按照…

mysql新手常見問題解決方法總結

1. 安裝與配置問題 1.1 無法安裝MySQL Server MySQL Server安裝失敗是新手常見的問題之一&#xff0c;以下是具體原因及解決方案&#xff1a; 系統要求不滿足&#xff1a;MySQL對操作系統有最低版本要求&#xff0c;如Windows 7 SP1及以上、macOS 10.13及以上。若系統版本過…

數字組合(信息學奧賽一本通-1291)

【題目描述】 有n個正整數&#xff0c;找出其中和為t(t也是正整數)的可能的組合方式。如&#xff1a;n5,5個數分別為1,2,3,4,5&#xff0c;t5&#xff1b;那么可能的組合有514和523和55三種組合方式。 【輸入】 輸入的第一行是兩個正整數n和t&#xff0c;用空格隔開&#xff0c…

搜索引擎(基于java在線文檔)

背景&#xff1a; 基于java文檔的搜索引擎&#xff0c;可以輸入搜索詞&#xff0c;然后就可以查詢出與搜索詞相關的文檔。該項目的最主要的工作是要構建索引&#xff0c;就是正排和倒排索引。正排索引&#xff1a;根據文檔id獲取到文檔&#xff1b;倒排索引&#xff1a;根據搜…

【每日學點HarmonyOS Next知識】web滾動、事件回調、selectable屬性、監聽H5內部router、Grid嵌套時高度設置

【每日學點HarmonyOS Next知識】web滾動、事件回調、selectable屬性、監聽H5內部router、Grid嵌套時高度設置 1、HarmonyOS WebView加載url無法滾動&#xff1f; scroll 里面嵌套webView&#xff0c;demo參考&#xff1a; // xxx.ets import web_webview from ohos.web.webv…

Flink性能指標詳解MetricsAnalysis

文章目錄 Flink 組成1.JobManager2.TaskManager3.ResourceManager4.Dispatcher5.Client6. Env JobManager MetricsTaskManager Metrics Flink 組成 1.JobManager 管理任務 作業調度&#xff1a;負責接收和調度作業&#xff0c;分配任務到 TaskManager。資源管理&#xff1a;…

Flutter底層實現

1. Dart 語言 Dart 是 Flutter 的主要編程語言。Dart 設計之初就是為了與 JavaScript 兼容&#xff0c;并且可以編譯為機器代碼運行。Dart 提供了一些特性&#xff0c;如異步支持&#xff08;通過 async 和 await&#xff09;&#xff0c;這使得編寫高效的網絡請求和復雜動畫變…

< 自用文兒 > CertBot 申請 SSL 證書 使用 challenge 模式 避開防火墻的阻擋

環境&#xff1a; 騰訊 VPS 騰訊會向你銷售 SSL &#xff0c; 這個本是免費的。CertBot 默認申請證書要用到 80 端口&#xff0c;會蹭邊什么什么條款&#xff0c;備案法律來阻止80端口的通訊&#xff0c;沒有網站也一樣被阻攔。 通過騰訊買的域名&#xff1a; bestherbs.cn …

【AI】【Unity】關于Unity接入DeepseekAPI遇到的坑

前言 由于deepseek網頁端在白天日常抽風&#xff0c;無法正常的使用&#xff0c;所以調用API就成了目前最好的選擇&#xff0c;尤其是Deepseek的API價格低得可怕&#xff0c;這不是和白送的一樣嗎&#xff01;然后使用過很多本地部署接入API的方式&#xff0c;例如Chatbox、Pa…

【微知】Mellanox驅動中to是什么?有哪些超時時間?(time out,心跳2s,reset 1分鐘)

to是tout縮寫&#xff0c;tout是time out 單位是毫秒。 static const u32 tout_def_sw_val[MAX_TIMEOUT_TYPES] {[MLX5_TO_FW_PRE_INIT_TIMEOUT_MS] 120000, # 2min。預初始化的總超時時間[MLX5_TO_FW_PRE_INIT_ON_RECOVERY_TIMEOUT_MS] 7200000, #設備恢復過程中的固件預初…

linux | Vim 命令快捷操作

注&#xff1a;本文為過去的 “vim 使用筆記”。 跳轉命令 跳轉命令 #&#xff1a;向前查找光標當前所在單詞&#xff0c;并跳轉到該單詞的上一個出現位置。*&#xff1a;向后查找光標當前所在單詞&#xff0c;并跳轉到該單詞的下一個出現位置。 行內跳轉 0&#xff1a;跳轉…

樹莓派3B+的初步使用

樹莓派3B的初步使用 一、安裝使用樹莓派系統1.將系統寫入SD卡2.登錄樹莓派系統3.用C和Python編譯運行hello world 一、安裝使用樹莓派系統 1.將系統寫入SD卡 首先&#xff0c;準備至少16GB大小的SD卡以便裝入樹莓派系統&#xff0c;將SD卡插入讀卡器后連接電腦準備給SD卡寫入…

基于Windows11的DockerDesktop安裝和布署方法簡介

基于Windows11的DockerDesktop安裝和布署方法簡介 一、下載安裝Docker docker 下載地址 https://www.docker.com/ Download Docker Desktop 選擇Download for Winodws AMD64下載Docker Desktop Installer.exe 雙點擊 Docker Desktop Installer.exe 進行安裝 測試Docker安裝是…

文檔處理控件Aspose.Total教程:使用 C# 將 Obsidian Markdown 轉換為 OneNote

Obsidian 是一款廣泛使用的基于 Markdown 的筆記應用程序。它提供了一種強大而有效的方式來構建和組織想法。用戶可以無縫地連接他們的想法&#xff0c;提高清晰度和工作效率。另一方面&#xff0c;OneNote 是 Microsoft 的一款功能強大的筆記應用程序。它還可以幫助用戶組織他…

第5章:vuex

第5章&#xff1a;vuex 1 求和案例 純vue版2 vuex工作原理圖3 vuex案例3.1 搭建vuex環境錯誤寫法正確寫法 3.2 求和案例vuex版細節分析源代碼 4 getters配置項4.1 細節4.2 源代碼 5 mapState與mapGetters5.1 總結5.2 細節分析5.3 源代碼 6 mapActions與mapMutations6.1 總結6.2…

迷你世界腳本對象庫接口:ObjectLib

對象庫接口&#xff1a;ObjectLib 迷你世界 更新時間: 2023-04-26 20:21:09 具體函數名及描述如下: 序號 函數名 函數描述 1 getAreaData(...) 獲取區域數據 2 getPositionData(...) 獲取位置數據 3 getLivingData(...) 獲取生物數據 4 getItemDat…

測試是如何跟進和管理 bug

測試在跟進和管理 Bug定位精確、問題反饋及時、修復閉環高效 三大關鍵環節中起到了至關重要的作用。Bug定位精確 是整個流程的基礎&#xff0c;通過詳細記錄和復現問題&#xff0c;可以幫助開發團隊迅速找出缺陷根源&#xff1b;而及時有效的反饋機制則確保問題不會被遺漏&…