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. Automatic scroll
Qt 6.11 is out! See what's new in the release blog

Automatic scroll

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 559 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.
  • C Offline
    C Offline
    Crabnewbula
    wrote on last edited by
    #1

    Hi guys I have a question regarding this code . I have taken this code from https://www.pythonguis.com/tutorials/plotting-pyqtgraph/. I want to know which part of code/code line is making graph to move in horizontal direction.

    from PyQt5 import QtWidgets, QtCore
    from pyqtgraph import PlotWidget, plot
    import pyqtgraph as pg
    import sys # We need sys so that we can pass argv to QApplication
    import os
    from random import randint

    class MainWindow(QtWidgets.QMainWindow):

    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
    
        self.graphWidget = pg.PlotWidget()
        self.setCentralWidget(self.graphWidget)
    
        self.x = list(range(100))  # 100 time points
        self.y = [randint(0,100) for _ in range(100)]  # 100 data points
    
        self.graphWidget.setBackground('w')
    
        pen = pg.mkPen(color=(255, 0, 0))
        self.data_line =  self.graphWidget.plot(self.x, self.y, pen=pen)
      
             # ... init continued ...
        
                self.timer = QtCore.QTimer()
        
                self.timer.setInterval(50)
        
                self.timer.timeout.connect(self.update_plot_data)
        
                self.timer.start()
        
        
        
            def update_plot_data(self):
        
        
        
                self.x = self.x[1:]  # Remove the first y element.
        
                self.x.append(self.x[-1] + 1)  # Add a new value 1 higher than the last.
        
        
        
                self.y = self.y[1:]  # Remove the first
        
                self.y.append( randint(0,100))  # Add a new random value.
        
        
        
                self.data_line.setData(self.x, self.y)  # Update the data.
                app = QtWidgets.QApplication(sys.argv)
                
                w = MainWindow()
                
                w.show()
                
                sys.exit(app.exec_())
    
    JonBJ 1 Reply Last reply
    0
    • C Crabnewbula

      Hi guys I have a question regarding this code . I have taken this code from https://www.pythonguis.com/tutorials/plotting-pyqtgraph/. I want to know which part of code/code line is making graph to move in horizontal direction.

      from PyQt5 import QtWidgets, QtCore
      from pyqtgraph import PlotWidget, plot
      import pyqtgraph as pg
      import sys # We need sys so that we can pass argv to QApplication
      import os
      from random import randint

      class MainWindow(QtWidgets.QMainWindow):

      def __init__(self, *args, **kwargs):
          super(MainWindow, self).__init__(*args, **kwargs)
      
          self.graphWidget = pg.PlotWidget()
          self.setCentralWidget(self.graphWidget)
      
          self.x = list(range(100))  # 100 time points
          self.y = [randint(0,100) for _ in range(100)]  # 100 data points
      
          self.graphWidget.setBackground('w')
      
          pen = pg.mkPen(color=(255, 0, 0))
          self.data_line =  self.graphWidget.plot(self.x, self.y, pen=pen)
        
               # ... init continued ...
          
                  self.timer = QtCore.QTimer()
          
                  self.timer.setInterval(50)
          
                  self.timer.timeout.connect(self.update_plot_data)
          
                  self.timer.start()
          
          
          
              def update_plot_data(self):
          
          
          
                  self.x = self.x[1:]  # Remove the first y element.
          
                  self.x.append(self.x[-1] + 1)  # Add a new value 1 higher than the last.
          
          
          
                  self.y = self.y[1:]  # Remove the first
          
                  self.y.append( randint(0,100))  # Add a new random value.
          
          
          
                  self.data_line.setData(self.x, self.y)  # Update the data.
                  app = QtWidgets.QApplication(sys.argv)
                  
                  w = MainWindow()
                  
                  w.show()
                  
                  sys.exit(app.exec_())
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Crabnewbula said in Automatic scroll:

      making graph to move in horizontal direction.

      Presumably when you add a point on the timer expiry via self.data_line.setData(self.x, self.y) # Update the data. if that self.x is over at the right the graph auto-scrolls to show it?

      On a separate note: if you are going to show Python code it is vital you do so with correct indentation. I am guessing your actual code is not as shown, at least for app = QtWidgets.QApplication(sys.argv) onward.

      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