Results 1 to 3 of 3

Thread: I'm trying to write a QPainter update Interval

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default I'm trying to write a QPainter update Interval

    I'm going to use the QPainter update to make the shape appear and hit, but if I run the thread, it won't come up. What's wrong with it?
    the part of a problem
    while not e.wait(1):
    self.update()

    Qt Code:
    1. import sys
    2. from PyQt5.QtWidgets import QWidget, QApplication , QPushButton, QVBoxLayout
    3. from PyQt5.QtGui import QPainter, QPen, QColor, QBrush
    4. from PyQt5.QtCore import Qt
    5. import numpy as np
    6.  
    7. import threading
    8.  
    9. class MyApp(QWidget):
    10.  
    11. def __init__(self):
    12. super().__init__()
    13. self.initUI()
    14.  
    15. def initUI(self):
    16. self.setGeometry(300, 300, 400, 400)
    17. self.setWindowTitle('Rect')
    18. self.show()
    19.  
    20. def paintEvent(self, e):
    21. qp = QPainter()
    22. qp.begin(self)
    23. self.draw_rect(qp)
    24. e = threading.Event()
    25. #the part of a problem
    26. while not e.wait(1):
    27. self.update()
    28. qp.end()
    29.  
    30.  
    31. def draw_rect(self, qp):
    32. qp.setBrush(QColor(0, 0, 0))
    33. for i in range(5):
    34. rand_x = 100 * np.random.randn()
    35. rand_y = 100 * np.random.randn()
    36. qp.drawRect(self.width() / 2 + rand_x, self.height() / 2 + rand_y, 10, 10)
    37.  
    38.  
    39.  
    40. if __name__ == '__main__':
    41. app = QApplication(sys.argv)
    42. ex = MyApp()
    43. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    Last edited by yskioi; 19th June 2020 at 17:39.

Similar Threads

  1. Replies: 6
    Last Post: 10th October 2016, 19:03
  2. Replies: 0
    Last Post: 28th September 2011, 08:14
  3. Replies: 3
    Last Post: 28th August 2010, 13:42
  4. Replies: 13
    Last Post: 29th April 2009, 16:51
  5. QPainter update()
    By csvivek in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2008, 10:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.