traqsinc
Gold Üye
- Katılım
- 26 Nis 2024
- Mesajlar
- 459
- Beğeniler
- 56
Gptyle yaptığım boş bir loader var rgb gradient widget eklemeye çalıştım ama rgb biraz sorunlu 2 saniye yanıyor sonra duruyor yapabilecek varmı 2 gram bilgimle yapamadım :/
class GradientWidget(QWidget):
def __init__(self):
super().__init__()
self.setAutoFillBackground(True)
# Başlangıç renkleri
self._start_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
self._end_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
# İlk gradyanı ayarla
self.gradient = QLinearGradient(0, 0, 0, self.height())
self.gradient.setColorAt(0.0, self._start_color)
self.gradient.setColorAt(1.0, self._end_color)
palette = QPalette()
palette.setBrush(QPalette.Window, QBrush(self.gradient))
self.setPalette(palette)
# Animasyonu başlat
self.color_animation = QPropertyAnimation(self, b"start_color")
self.color_animation.setDuration(2000) # 2 saniye
self.color_animation.setStartValue(self._start_color)
self.color_animation.setEndValue(self._end_color)
self.color_animation.start()
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
pen = QPen(QColor(61, 142, 185, 60), 1) # Beyaz renkte ve düşük opaklıkta çizgiler
painter.setPen(pen)
# Eğimli çizgileri çiz
spacing = 20 # Çizgiler arasındaki mesafe
for i in range(0, self.width(), spacing):
start_point = QPoint(i, 0)
end_point = QPoint(i - 100, self.height()) # Eğimli görünüm için x koordinatını ayarladık
painter.drawLine(start_point, end_point)
@pyqtProperty(QColor)
def start_color(self):
return self._start_color
@start_color.setter
def start_color(self, color):
self._start_color = color
self.update_gradient()
@pyqtProperty(QColor)
def end_color(self):
return self._end_color
@end_color.setter
def end_color(self, color):
self._end_color = color
self.update_gradient()
def update_gradient(self):
# Gradyanı her güncellediğimizde palette'i yeniliyoruz
self.gradient.setColorAt(0.0, self._start_color)
self.gradient.setColorAt(1.0, self._end_color)
palette = QPalette()
palette.setBrush(QPalette.Window, QBrush(self.gradient))
self.setPalette(palette)
def on_animation_finished(self):
# Animasyon bittiğinde yeni rastgele renkler seç
self._start_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
self._end_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
# Yeni renkler ile animasyonu yeniden başlat
self.color_animation.setStartValue(self._start_color)
self.color_animation.setEndValue(self._end_color)
self.color_animation.start()
class GradientWidget(QWidget):
def __init__(self):
super().__init__()
self.setAutoFillBackground(True)
# Başlangıç renkleri
self._start_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
self._end_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
# İlk gradyanı ayarla
self.gradient = QLinearGradient(0, 0, 0, self.height())
self.gradient.setColorAt(0.0, self._start_color)
self.gradient.setColorAt(1.0, self._end_color)
palette = QPalette()
palette.setBrush(QPalette.Window, QBrush(self.gradient))
self.setPalette(palette)
# Animasyonu başlat
self.color_animation = QPropertyAnimation(self, b"start_color")
self.color_animation.setDuration(2000) # 2 saniye
self.color_animation.setStartValue(self._start_color)
self.color_animation.setEndValue(self._end_color)
self.color_animation.start()
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
pen = QPen(QColor(61, 142, 185, 60), 1) # Beyaz renkte ve düşük opaklıkta çizgiler
painter.setPen(pen)
# Eğimli çizgileri çiz
spacing = 20 # Çizgiler arasındaki mesafe
for i in range(0, self.width(), spacing):
start_point = QPoint(i, 0)
end_point = QPoint(i - 100, self.height()) # Eğimli görünüm için x koordinatını ayarladık
painter.drawLine(start_point, end_point)
@pyqtProperty(QColor)
def start_color(self):
return self._start_color
@start_color.setter
def start_color(self, color):
self._start_color = color
self.update_gradient()
@pyqtProperty(QColor)
def end_color(self):
return self._end_color
@end_color.setter
def end_color(self, color):
self._end_color = color
self.update_gradient()
def update_gradient(self):
# Gradyanı her güncellediğimizde palette'i yeniliyoruz
self.gradient.setColorAt(0.0, self._start_color)
self.gradient.setColorAt(1.0, self._end_color)
palette = QPalette()
palette.setBrush(QPalette.Window, QBrush(self.gradient))
self.setPalette(palette)
def on_animation_finished(self):
# Animasyon bittiğinde yeni rastgele renkler seç
self._start_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
self._end_color = QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
# Yeni renkler ile animasyonu yeniden başlat
self.color_animation.setStartValue(self._start_color)
self.color_animation.setEndValue(self._end_color)
self.color_animation.start()