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. SetSceneRect doesn't seem to work (PyQt)

SetSceneRect doesn't seem to work (PyQt)

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.6k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    Jeeves
    wrote on last edited by
    #1

    Hi,

    I'm having a hard time getting setSceneRect to work on a QGraphicsView Widget. Here's my program:

    @#!/usr/bin/env python

    -- coding: utf-8 --

    import sys, time, math

    from PyQt4.QtGui import QApplication, QGraphicsView, QGraphicsScene, QPainter
    from PyQt4.QtCore import QTimer
    from PyQt4.QtOpenGL import QGLWidget

    class App(QApplication):
    def init(self, args):
    QApplication.init(self, args)

    self._t0 = time.time()
    self._last_point = None
    
    self._scene = QGraphicsScene(self)
    self._view = QGraphicsView(self._scene)
    
    self._timer = QTimer(self)
    self._timer.timeout.connect(self._on_timeout)
    self._timer.setInterval(100)
    self._timer.start()
    
    self._view.show()
    

    def _on_timeout(self):
    x = time.time() - self._t0
    y = math.sin(0.1 * x * 2 * math.pi)

    if self._last_point is not None:
      self._scene.addLine(self._last_point['x'], self._last_point['y'], x, y)
      self._view.setSceneRect(x - 20, -1, 20, 2)  # Show the last 20 seconds
    
    self._last_point = { 'x': x, 'y': y }
    

    if name == 'main':
    app = App(sys.argv)

    app.exec_()
    @

    This creates a sine wave in a QGraphicsScene, and shows it using a QGraphicsView. The plan is to show the last 20 seconds and the full vertical range of the plot, so on line 33 I set the horizontal and vertical viewing range using setSceneRect on the QGraphicsView. But the graph is still minuscule in the center of the window. Can someone tell me what I'm doing wrong? Is there a better way to achieve this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      adnako
      wrote on last edited by
      #2

      5.4.2 still doesn't work

      1 Reply Last reply
      0

      • Login

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