pos機卡交互失敗

 新聞資訊2  |   2023-08-05 10:37  |  投稿人:pos機之家

網上有很多關于pos機卡交互失敗,QChart圖表之對圖表進行交互操作的知識,也有很多人為大家解答關于pos機卡交互失敗的問題,今天pos機之家(www.bangarufamily.com)為大家整理了關于這方面的知識,讓我們一起來看下吧!

本文目錄一覽:

1、pos機卡交互失敗

pos機卡交互失敗

圖表交互操作

在圖表可視化中,一些場景中需要對圖表進行交互操作,QChart的各種圖表類繼承自Qt的GraphicsView 框架,因此可以很方便對圖表中的各種元素進行進行交互操作,例如,可以使用鼠標拖動QLineSeries圖形序列中的某個點,改變其值,并在圖表中交互顯示。

使用鼠標進行交互操作,需要在繼承自QChartView的類中重新實現三個和鼠標有關的事件函數,它們是mousePressEvent(), mouseMoveEvent()和MouseReleaseEvent(), 記錄鼠標移動的點,將其傳送給QChart類,然后就其轉換成對應圖標序列坐標的點,替換序列中相應的點值,就可以實現交互對圖表的交互操作。

折線交互操作示例

示例代碼演示了如何使用鼠標來交互調整QLineSeries中的點,并在圖表中動態顯示出來。完整代碼如下:

import sys, mathfrom PyQt5.QtCore import Qt, Qpoint, QPointFfrom PyQt5.QtGui import QPainter, QPenfrom PyQt5.QtWidgets import QApplication, QMainwindowfrom  PyQt5.QtChart import QChart, QChartView, QLineSeries, QAbstractAxis, QValueAxis class MyChart(QChart):    def __init__(self, parent=None):        super(MyChart, self).__init__(parent)        self.clicked = False            def clickPoint(self, point):        series = self.series()[0]        if series is None:            return                #找到最近的點        self.movingPoint = QPoint()        self.clicked = False                points = series.pointsVector()        for pnt in points:            if self.distance(pnt, point) < self.distance(self.movingPoint, point):                self.movingPoint = pnt                self.clicked = True       def distance(self, p1, p2):        dx = p1.x() - p2.x()        dy = p1.y() - p2.y()        return  math.sqrt(dx * dx + dy * dy)        def setPointClicked(self, clicked):        self.clicked = clicked            def handlePointMove(self, point):        if not self.clicked:            return        #將從ChartView中單擊的點映射到圖表所占據的區域。        mappedPoint = point        mappedPoint.setX(point.x() - self.plotArea().x())        mappedPoint.setY(point.y() - self.plotArea().y())                #獲取x軸和y軸,以便能夠將映射的坐標點轉換為圖表比例。        axisX = self.axes(Qt.Horizontal)[0]        hAxis = None        if axisX.type() == QAbstractAxis.AxisTypeValue:            hAxis = axisX                    axisY = self.axes(Qt.Vertical)[0]        vAxis = None        if axisY.type() == QAbstractAxis.AxisTypeValue:            vAxis = axisY                    if hAxis and vAxis:            #計算在x軸和y軸上兩點的單位因子            xUnit = self.plotArea().width="360px",height="auto" />

運行結果如下圖:

本文知識點使用QLineSerie.replace()方法對其中的點進行動態替換。使用鼠標對圖表進行交互控制。

請多多關注,評論,收藏,點贊,和轉發。

前一篇: 實戰PyQt5: 159-使用OpenGL加速圖表繪制

以上就是關于pos機卡交互失敗,QChart圖表之對圖表進行交互操作的知識,后面我們會繼續為大家整理關于pos機卡交互失敗的知識,希望能夠幫助到大家!

轉發請帶上網址:http://www.bangarufamily.com/newsone/94656.html

你可能會喜歡:

版權聲明:本文內容由互聯網用戶自發貢獻,該文觀點僅代表作者本人。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如發現本站有涉嫌抄襲侵權/違法違規的內容, 請發送郵件至 babsan@163.com 舉報,一經查實,本站將立刻刪除。