yskioi
19th June 2020, 17:23
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()
import sys
from PyQt5.QtWidgets import QWidget, QApplication , QPushButton, QVBoxLayout
from PyQt5.QtGui import QPainter, QPen, QColor, QBrush
from PyQt5.QtCore import Qt
import numpy as np
import threading
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 400, 400)
self.setWindowTitle('Rect')
self.show()
def paintEvent(self, e):
qp = QPainter()
qp.begin(self)
self.draw_rect(qp)
e = threading.Event()
#the part of a problem
while not e.wait(1):
self.update()
qp.end()
def draw_rect(self, qp):
qp.setBrush(QColor(0, 0, 0))
for i in range(5):
rand_x = 100 * np.random.randn()
rand_y = 100 * np.random.randn()
qp.drawRect(self.width() / 2 + rand_x, self.height() / 2 + rand_y, 10, 10)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
the part of a problem
while not e.wait(1):
self.update()
import sys
from PyQt5.QtWidgets import QWidget, QApplication , QPushButton, QVBoxLayout
from PyQt5.QtGui import QPainter, QPen, QColor, QBrush
from PyQt5.QtCore import Qt
import numpy as np
import threading
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 400, 400)
self.setWindowTitle('Rect')
self.show()
def paintEvent(self, e):
qp = QPainter()
qp.begin(self)
self.draw_rect(qp)
e = threading.Event()
#the part of a problem
while not e.wait(1):
self.update()
qp.end()
def draw_rect(self, qp):
qp.setBrush(QColor(0, 0, 0))
for i in range(5):
rand_x = 100 * np.random.randn()
rand_y = 100 * np.random.randn()
qp.drawRect(self.width() / 2 + rand_x, self.height() / 2 + rand_y, 10, 10)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())