def capture(self, fullScreen = False, filename = ''): if fullScreen: image = QApplication.primaryScreen().grabWindow(0) else: image = QImage(self.webView.mainFrame.contentsSize(), QImage.Format_ARGB32) painter = QPainter(image) self.webView.mainFrame.render(painter) painter.end() if filename: return image.save(filename) else: data = QByteArray() buffer = QBuffer(data) buffer.open(QBuffer.WriteOnly) image.save(buffer, 'PNG') return bytes(data.toBase64()).decode()
def mousePressEvent(self, e: QMouseEvent): self.tmp_pos = e.pos() def mouseMoveEvent(self, e: QMouseEvent): # self.diff_pos = e.pos() - self.diff_pos # print(diff+self.pos()) mouse_pos = self.pos() + e.pos() self.move(mouse_pos - self.tmp_pos) if __name__ == '__main__': app = QApplication(sys.argv) agent = list() n = 50 random_x = numpy.random.rand(n) random_y = numpy.random.rand(n) screen = app.primaryScreen() # type:QScreen screen_height = screen.geometry().height() screen_width = screen.geometry().width() for i in range(n): j = Agent() j.move(QPoint(random_x[i] * screen_width, random_y[i] * screen_height)) j.show() agent.append(j) sys.exit(app.exec())