Insérer graphique interface qt5 2

Fermé
yclem - Modifié le 17 déc. 2020 à 12:49
Phil_1857 Messages postés 1883 Date d'inscription lundi 23 mars 2020 Statut Membre Dernière intervention 28 février 2024 - 17 déc. 2020 à 12:56
Bonjour,
je ne comprend pas pourquoi mon graphique ne s'affiche pas dans ma fenetre alors que les boutons s'affiche dans la fenêtre. Je suis débutant en python merci pour vos reponse.
Le graphique est initialiser avec PyQtgraph. Qaund j execute mon code 2 fenetre s'oubre le graphique et une autre fenetre avec le bouton.

from PyQt5.QtWidgets import  QListWidget, QLabel,  QPushButton
import pyqtgraph as pg
from collections import deque
from pyqtgraph.Qt import QtGui
import numpy as np
import sys
from PyQt5.QtWidgets import QMainWindow, QPlainTextEdit
from PyQt5 import QtWidgets

class Window(QMainWindow):
global mess
def __init__(self):
super().__init__()

self.setWindowTitle("fenetre1")
self.setGeometry(300,500,800,750)

self.MyUI()



def MyUI(self):


g=self.Graph() #graphique appeler dans la fonction MyUI

button = QPushButton("sauvegarder", self)#initialisation du bouton
button.clicked.connect(self.appui_bouton1)
button.setStyleSheet("background-color: yellow;font-size:18px;font-family:Impact;")
button.resize(150,50)
button.move(1100, 100)

button2 = QPushButton("supprimer", self)
button2.clicked.connect(self.appui_bouton2)
button2.setStyleSheet("background-color: red;font-size:18px;font-family:Impact;")
button2.resize(150,50)
button2.move(1100, 180)

button3 = QPushButton("suivant", self)
button3.clicked.connect(self.appui_bouton3)
button3.setStyleSheet("background-color: green;font-size:18px;font-family:Impact;")
button3.resize(150,50)
button3.move(1100, 260)






def appui_bouton1(self):
print("le fichier a été sauvergarder")


def appui_bouton2(self):
print("le fichier a été supprimer")
#os.remove("graph2.png")


def appui_bouton3(self):
print("suivant")



def Graph(self):

self.dat = deque()
self.maxLen = 50#max number of data points to show on graph
self.app = QtGui.QApplication([])
self.win = pg.GraphicsWindow()
self.win.setWindowTitle('graph1')

self.label = pg.LabelItem(justify='right')
self.win.addItem(self.label)

self.p1 = self.win.addPlot(row=1, col=0)
self.win.nextRow()

self.region = pg.LinearRegionItem()
self.region.setZValue(10)
self.p1.setAutoVisible(y=True)
#plt.axis([-1,1,-3,3])
self.x=np.linspace(0,23,15000)
self.data1 = np.cos(self.x)
self.p1.showGrid(x=True, y=True)
self.p1.plot(self.data1, pen="y")




def updateRegion(window, viewRange):
rgn = viewRange[0]
self.region.setRegion(rgn)

self.p1.sigRangeChanged.connect(updateRegion)
self.region.setRegion([1000, 2000])


vLine = pg.InfiniteLine(angle=90, movable=False)
hLine = pg.InfiniteLine(angle=0, movable=False)
self.p1.addItem(vLine, ignoreBounds=True)
self.p1.addItem(hLine, ignoreBounds=True)

vb = self.p1.vb



def mouseMoved(evt):
pos = evt[0] ## using signal proxy turns original arguments into a tuple
if self.p1.sceneBoundingRect().contains(pos):
mousePoint = vb.mapSceneToView(pos)
index = int(mousePoint.x())
if index > 0 and index < len(self.data1):
self.label.setText("<span style='font-size: 12pt'><span style='color: yellow'>x=%0.1f,
<span style='color: yellow'>y1=%0.1f</span>" % (mousePoint.x(), self.data1[index]))
vLine.setPos(mousePoint.x())
hLine.setPos(mousePoint.y())





proxy = pg.SignalProxy(self.p1.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)

#QtGui.QApplication.instance().exec_()


if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = Window()
mainWin.show()
sys.exit( app.exec_() )


Configuration: Windows / Chrome 87.0.4280.66
A voir également:

1 réponse

Phil_1857 Messages postés 1883 Date d'inscription lundi 23 mars 2020 Statut Membre Dernière intervention 28 février 2024 178
Modifié le 17 déc. 2020 à 12:59
Bonjour,

merci de poster ton code complet avec les balises de code
mode d'emploi:
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

Visuellement, ça doit ressembler à ceci (avec la coloration syntaxique) :

def test():
    print('test')

test()


Tu vois que ça ne ressemble pas à ce que tu as fais:
0