Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add stop button to pyqtgraph?
Qt 6.11 is out! See what's new in the release blog

How to add stop button to pyqtgraph?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    poordev123
    wrote on last edited by
    #1

    I have a program that launches a graph using pyqtgraphing as a pyside2 qt application. What I want to happen is to have the user hit a button and that makes the graph stop. I am setting up the graph like this

    def set_up_graph(self):
            QApplication.setAttribute(QtCore.Qt.AA_Use96Dpi)
            pg.setConfigOption('background', 'w')
            pg.setConfigOption('foreground', 'k')
            plot = pg.plot()
            plot.setLabel('bottom', 'Frequency')
            plot.setLabel('left', 'Power Value')
            plot.setWindowTitle('Frequency vs Power Graph')
    

    And then I am actually doing the graphing using this function

    def plot_the_graph(self):
        power_vals = [1,2,3,4]
        frequency_values = [5,6,7,8]
        plot.plot(frequency_values, power_vals, clear=True, pen=pg.mkPen('g', width=1.5), symbol='x', name="Power Vs. Frequency")
        QtGui.QGuiApplication.processEvents()
    

    And then I have one other function that determines what button the user has hit

        def multi_graph(self):
            if self.multi:
                self.plot_the_graph()
            self.multi_graph()
    

    I want to add a stop button to these graphs so then I can have it be when the user hits stop then self.multi = False, and then the graph would stop. I can't find a way to just add a stop button to this though.

    Currently what's happening is that the graph will just run and run and then eventually I will have 60 popup windows of the graph and I will have to force stop it.

    jsulmJ 1 Reply Last reply
    0
    • P poordev123

      I have a program that launches a graph using pyqtgraphing as a pyside2 qt application. What I want to happen is to have the user hit a button and that makes the graph stop. I am setting up the graph like this

      def set_up_graph(self):
              QApplication.setAttribute(QtCore.Qt.AA_Use96Dpi)
              pg.setConfigOption('background', 'w')
              pg.setConfigOption('foreground', 'k')
              plot = pg.plot()
              plot.setLabel('bottom', 'Frequency')
              plot.setLabel('left', 'Power Value')
              plot.setWindowTitle('Frequency vs Power Graph')
      

      And then I am actually doing the graphing using this function

      def plot_the_graph(self):
          power_vals = [1,2,3,4]
          frequency_values = [5,6,7,8]
          plot.plot(frequency_values, power_vals, clear=True, pen=pg.mkPen('g', width=1.5), symbol='x', name="Power Vs. Frequency")
          QtGui.QGuiApplication.processEvents()
      

      And then I have one other function that determines what button the user has hit

          def multi_graph(self):
              if self.multi:
                  self.plot_the_graph()
              self.multi_graph()
      

      I want to add a stop button to these graphs so then I can have it be when the user hits stop then self.multi = False, and then the graph would stop. I can't find a way to just add a stop button to this though.

      Currently what's happening is that the graph will just run and run and then eventually I will have 60 popup windows of the graph and I will have to force stop it.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @poordev123 said in How to add stop button to pyqtgraph?:

      plot = pg.plot()

      This is local variable in set_up_graph(self).
      So, it is not hte same used in plot_the_graph(self).

      I never used PyQtgraph but according to its documentation you should rather do like this:

      pw = pg.plot(xVals, yVals, pen='r')  # plot x vs y in red
      pw.plot(xVals, yVals2, pen='b')
      
      win = pg.GraphicsWindow()  # Automatically generates grids with multiple items
      win.addPlot(data1, row=0, col=0)
      win.addPlot(data2, row=0, col=1)
      win.addPlot(data3, row=1, col=0, colspan=2)
      
      pg.show(imageData
      

      instead of calling static plot() which creates a new plot at each call.
      I suggest you spend some time to read:
      https://pyqtgraph.readthedocs.io/en/latest/how_to_use.html
      as it is not part of Qt.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved