перепиши следующий код под PySide6: import sys from PyQt5.QtWidgets import QApplication,…
- User
перепиши следующий код под PySide6: import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton from PyQt5.QtGui import QPainter, QBrush, QColor, QPen from PyQt5.QtCore import Qt, QTimer, QRect import random class DrawingWindow(QMainWindow): def init(self, coordinates): super().init() self.setWindowTitle("Transparent Drawing Window") self.setGeometry(0, 0, QApplication.desktop().screenGeometry().width(), QApplication.desktop().screenGeometry().height()) self.setAttribute(Qt.WA_TranslucentBackground, True) self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.painter = QPainter() self.painter.setRenderHint(QPainter.Antialiasing) self.pen_color = QColor(255, 0, 0) # Set the initial pen color to red self.pen_width = 4 # Set the initial pen width to 4 self.coordinates = coordinates # Store the coordinates for drawing rectangles self.starting_point = None self.red_button = QPushButton('Red', self) self.red_button.clicked.connect(self.set_red_color) self.blue_button = QPushButton('Blue', self) self.blue_button.clicked.connect(self.set_blue_color) def set_red_color(self): self.pen_color = QColor(255, 0, 0) self.update() def set_blue_color(self): self.pen_color = QColor(0, 0, 255) self.update() def paintEvent(self, event): self.painter.begin(self) self.painter.setPen(Qt.NoPen) self.painter.setBrush(QBrush(Qt.transparent)) self.painter.drawRect(QRect(0, 0, self.width(), self.height())) # Draw a transparent background self.painter.setPen(QPen(QColor(self.pen_color), self.pen_width)) self.painter.setBrush(QBrush(Qt.transparent)) self.red_button.move(self.coordinates[0], self.coordinates[1]) self.red_button.resize(50, 50) self.blue_button.move(self.coordinates[0] + 50, self.coordinates[1]) self.blue_button.resize(50, 50) self.painter.drawRect(self.coordinates[0], self.coordinates[1], self.coordinates[2], self.coordinates[3]) # Draw rectangles using the provided coordinates self.painter.end() def mousePressEvent(self, event): self.starting_point = event.pos() def mouseMoveEvent(self, event): if self.starting_point: current_point = event.pos() last_x = self.coordinates[0] + self.coordinates[2] first_x = self.coordinates[0] cur_x = current_point.x() cur_y = current_point.y() if cur_x < first_x: self.coordinates[2] += abs(cur_x - first_x) self.coordinates[0] = cur_x self.update() def mouseReleaseEvent(self, event): self.starting_point = None - Assistant
import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton from PySide6.QtGui import QPainter, QBrush, QColor, QPen from PySide6.QtCore import Qt, QRect import random
class DrawingWindow(QMainWindow): def init(self, coordinates): super().init() self.setWindowTitle("Transparent Drawing Window") self.setGeometry(0, 0, QApplication.primaryScreen().size().width(), QApplication.primaryScreen().size().height()) self.setAttribute(Qt.WA_TranslucentBackground, True) self.setWindowFlag(Qt.FramelessWindowHint) self.setWindowFlag(Qt.WindowStaysOnTopHint)
self.painter = QPainter() self.painter.setRenderHint(QPainter.Antialiasing) self.pen_color = QColor(255, 0, 0) # Set the initial pen color to red self.pen_width = 4 # Set the initial pen width to 4 self.coordinates = coordinates # Store the coordinates for drawing rectangles self.starting_point = None self.red_button = QPushButton('Red', self) self.red_button.clicked.connect(self.set_red_color) self.red_button.move(coordinates[0], coordinates[1]) self.blue_button = QPushButton('Blue', self) self.blue_button.clicked.connect(self.set_blue_color) self.blue_button.move(coordinates[0] + 50, coordinates[1]) def set_red_color(self): self.pen_color = QColor(255, 0, 0) self.update() def set_blue_color(self): self.pen_color = QColor(0, 0, 255) self.update() def paintEvent(self, event): self.painter.begin(self) self.painter.setPen(Qt.NoPen) self.painter.setBrush(QBrush(Qt.transparent)) self.painter.drawRect(QRect(0, 0, self.width(), self.height())) # Draw a transparent background self.painter.setPen(QPen(self.pen_color, self.pen_width)) self.painter.setBrush(QBrush(Qt.transparent)) self.painter.drawRect(self.coordinates[0], self.coordinates[1], self.coordinates[2], self.coordinates[3]) # Draw rectangles using the provided coordinates self.painter.end() def mousePressEvent(self, event): self.starting_point = event.pos() def mouseMoveEvent(self, event): if self.starting_point: current_point = event.pos() last_x = self.coordinates[0] + self.coordinates[2] first_x = self.coordinates[0] cur_x = current_point.x() cur_y = current_point.y() if cur_x < first_x: self.coordinates[2] += abs(cur_x - first_x) self.coordinates[0] = cur_x self.update() def mouseReleaseEvent(self, event): self.starting_point = Noneif name == "main": app = QApplication(sys.argv) window = DrawingWindow([100, 100, 200, 200]) window.show() sys.exit(app.exec())
- User
с форматированием
- Assistant
import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton from PySide6.QtGui import QPainter, QBrush, QColor, QPen from PySide6.QtCore import Qt, QRect import random class DrawingWindow(QMainWindow): def __init__(self, coordinates): super().__init__() self.setWindowTitle("Transparent Drawing Window") self.setGeometry(0, 0, QApplication.primaryScreen().size().width(), QApplication.primaryScreen().size().height()) self.setAttribute(Qt.WA_TranslucentBackground, True) self.setWindowFlag(Qt.FramelessWindowHint) self.setWindowFlag(Qt.WindowStaysOnTopHint) self.painter = QPainter() self.painter.setRenderHint(QPainter.Antialiasing) self.pen_color = QColor(255, 0, 0) # Set the initial pen color to red self.pen_width = 4 # Set the initial pen width to 4 self.coordinates = coordinates # Store the coordinates for drawing rectangles self.starting_point = None self.red_button = QPushButton('Red', self) self.red_button.clicked.connect(self.set_red_color) self.red_button.move(coordinates[0], coordinates[1]) self.blue_button = QPushButton('Blue', self) self.blue_button.clicked.connect(self.set_blue_color) self.blue_button.move(coordinates[0] + 50, coordinates[1]) def set_red_color(self): self.pen_color = QColor(255, 0, 0) self.update() def set_blue_color(self): self.pen_color = QColor(0, 0, 255) self.update() def paintEvent(self, event): self.painter.begin(self) self.painter.setPen(Qt.NoPen) self.painter.setBrush(QBrush(Qt.transparent)) self.painter.drawRect(QRect(0, 0, self.width(), self.height())) # Draw a transparent background self.painter.setPen(QPen(self.pen_color, self.pen_width)) self.painter.setBrush(QBrush(Qt.transparent)) self.painter.drawRect(self.coordinates[0], self.coordinates[1], self.coordinates[2], self.coordinates[3]) # Draw rectangles using the provided coordinates self.painter.end() def mousePressEvent(self, event): self.starting_point = event.pos() def mouseMoveEvent(self, event): if self.starting_point: current_point = event.pos() last_x = self.coordinates[0] + self.coordinates[2] first_x = self.coordinates[0] cur_x = current_point.x() cur_y = current_point.y() if cur_x < first_x: self.coordinates[2] += abs(cur_x - first_x) self.coordinates[0] = cur_x self.update() def mouseReleaseEvent(self, event): self.starting_point = None if __name__ == "__main__": app = QApplication(sys.argv) window = DrawingWindow([100, 100, 200, 200]) window.show() sys.exit(app.exec())
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.