Spinn Code
Loading Please Wait
  • Home
  • My Profile

Share something

Explore Qt Development Topics

  • Installation and Setup
  • Core GUI Components
  • Qt Quick and QML
  • Event Handling and Signals/Slots
  • Model-View-Controller (MVC) Architecture
  • File Handling and Data Persistence
  • Multimedia and Graphics
  • Threading and Concurrency
  • Networking
  • Database and Data Management
  • Design Patterns and Architecture
  • Packaging and Deployment
  • Cross-Platform Development
  • Custom Widgets and Components
  • Qt for Mobile Development
  • Integrating Third-Party Libraries
  • Animation and Modern App Design
  • Localization and Internationalization
  • Testing and Debugging
  • Integration with Web Technologies
  • Advanced Topics

About Developer

Khamisi Kibet

Khamisi Kibet

Software Developer

I am a computer scientist, software developer, and YouTuber, as well as the developer of this website, spinncode.com. I create content to help others learn and grow in the field of software development.

If you enjoy my work, please consider supporting me on platforms like Patreon or subscribing to my YouTube channel. I am also open to job opportunities and collaborations in software development. Let's build something amazing together!

  • Email

    infor@spinncode.com
  • Location

    Nairobi, Kenya
cover picture
profile picture Bot SpinnCode

7 Months ago | 69 views

**Topic: Custom Widgets and Components** In this example, we will create a custom animated circular progress bar widget using PyQt6. This widget will have properties for minimum and maximum values, current value, and colors for the progress bar and background. **Circular Progress Bar Widget** ```python import sys from PyQt6.QtCore import Qt, QTimer, pyqtProperty from PyQt6.QtGui import QPainter, QPen, QBrush, QColor from PyQt6.QtWidgets import QWidget class CircularProgressBar(QWidget): def __init__(self, parent=None): super().__init__(parent) self._min_value = 0 self._max_value = 100 self._value = 0 self._progress_color = QColor(0, 170, 255) self._background_color = QColor(50, 50, 50) self._animation_duration = 1000 # milliseconds self._animation_timer = QTimer() self._animation_timer.timeout.connect(self.animate) self._animation_step = 0 self.setFixedWidth(200) self.setFixedHeight(200) def start_animation(self): self._animation_timer.start(16) # 60 FPS def stop_animation(self): self._animation_timer.stop() self._animation_step = 0 def animate(self): self._animation_step += 1 if self._animation_step > self._max_value: self._animation_step = 0 self._value = self._animation_step self.update() @pyqtProperty(int) def maxValue(self): return self._max_value @maxValue.setter def maxValue(self, value): self._max_value = value @pyqtProperty(int) def minValue(self): return self._min_value @minValue.setter def minValue(self, value): self._min_value = value @pyqtProperty(int) def value(self): return self._value @value.setter def value(self, value): self._value = value self.update() @pyqtProperty(QColor) def progressColor(self): return self._progress_color @progressColor.setter def progressColor(self, color): self._progress_color = color self.update() @pyqtProperty(QColor) def backgroundColor(self): return self._background_color @backgroundColor.setter def backgroundColor(self, color): self._background_color = color self.update() def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(painter.Antialiasing) painter.setPen(QPen(Qt.PenStyle.NoPen)) painter.setBrush(QBrush(self._background_color)) painter.drawEllipse(10, 10, self.width() - 20, self.height() - 20) painter.setPen(QPen(self._progress_color, 10, Qt.PenCapStyle.RoundCap)) angle = (self._value / self._max_value) * 360 painter.drawPie(10, 10, self.width() - 20, self.height() - 20, 90 * 16, angle * 16) if __name__ == "__main__": from PyQt6.QtWidgets import QApplication app = QApplication(sys.argv) window = CircularProgressBar() window.show() window.start_animation() sys.exit(app.exec()) ``` **Explanation and Demonstration** In this example, we create a custom CircularProgressBar widget that inherits from QWidget. We define properties for minimum and maximum values, current value, and colors for the progress bar and background. The `start_animation` and `stop_animation` methods are used to start and stop the animation of the progress bar. The `animate` method is called at regular intervals using a QTimer to animate the progress bar. In the `paintEvent` method, we draw the circular progress bar using a QPainter. We demonstrate the use of this custom widget by creating an application with a single CircularProgressBar widget. **Screen Shot** Here's a screen shot of the running application: The application displays a circular progress bar that animates from 0 to 100%. To run this code, save it in a file called `circularprogressbar.py` and run it using Python: ```bash python circularprogressbar.py ``` This code will create a new application window with a circular progress bar that animates from 0 to 100%.
Daily Tip

Custom Animated Circular Progress Bar

**Topic: Custom Widgets and Components** In this example, we will create a custom animated circular progress bar widget using PyQt6. This widget will have properties for minimum and maximum values, current value, and colors for the progress bar and background. **Circular Progress Bar Widget** ```python import sys from PyQt6.QtCore import Qt, QTimer, pyqtProperty from PyQt6.QtGui import QPainter, QPen, QBrush, QColor from PyQt6.QtWidgets import QWidget class CircularProgressBar(QWidget): def __init__(self, parent=None): super().__init__(parent) self._min_value = 0 self._max_value = 100 self._value = 0 self._progress_color = QColor(0, 170, 255) self._background_color = QColor(50, 50, 50) self._animation_duration = 1000 # milliseconds self._animation_timer = QTimer() self._animation_timer.timeout.connect(self.animate) self._animation_step = 0 self.setFixedWidth(200) self.setFixedHeight(200) def start_animation(self): self._animation_timer.start(16) # 60 FPS def stop_animation(self): self._animation_timer.stop() self._animation_step = 0 def animate(self): self._animation_step += 1 if self._animation_step > self._max_value: self._animation_step = 0 self._value = self._animation_step self.update() @pyqtProperty(int) def maxValue(self): return self._max_value @maxValue.setter def maxValue(self, value): self._max_value = value @pyqtProperty(int) def minValue(self): return self._min_value @minValue.setter def minValue(self, value): self._min_value = value @pyqtProperty(int) def value(self): return self._value @value.setter def value(self, value): self._value = value self.update() @pyqtProperty(QColor) def progressColor(self): return self._progress_color @progressColor.setter def progressColor(self, color): self._progress_color = color self.update() @pyqtProperty(QColor) def backgroundColor(self): return self._background_color @backgroundColor.setter def backgroundColor(self, color): self._background_color = color self.update() def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(painter.Antialiasing) painter.setPen(QPen(Qt.PenStyle.NoPen)) painter.setBrush(QBrush(self._background_color)) painter.drawEllipse(10, 10, self.width() - 20, self.height() - 20) painter.setPen(QPen(self._progress_color, 10, Qt.PenCapStyle.RoundCap)) angle = (self._value / self._max_value) * 360 painter.drawPie(10, 10, self.width() - 20, self.height() - 20, 90 * 16, angle * 16) if __name__ == "__main__": from PyQt6.QtWidgets import QApplication app = QApplication(sys.argv) window = CircularProgressBar() window.show() window.start_animation() sys.exit(app.exec()) ``` **Explanation and Demonstration** In this example, we create a custom CircularProgressBar widget that inherits from QWidget. We define properties for minimum and maximum values, current value, and colors for the progress bar and background. The `start_animation` and `stop_animation` methods are used to start and stop the animation of the progress bar. The `animate` method is called at regular intervals using a QTimer to animate the progress bar. In the `paintEvent` method, we draw the circular progress bar using a QPainter. We demonstrate the use of this custom widget by creating an application with a single CircularProgressBar widget. **Screen Shot** Here's a screen shot of the running application: The application displays a circular progress bar that animates from 0 to 100%. To run this code, save it in a file called `circularprogressbar.py` and run it using Python: ```bash python circularprogressbar.py ``` This code will create a new application window with a circular progress bar that animates from 0 to 100%.

Images

More from Bot

Haskell Primitive Types.
7 Months ago 49 views
Angular Routing Fundamentals
7 Months ago 47 views
Integrating Third-Party Libraries: Creating a Sentiment Analysis Tool with TensorFlow and PyQt6
7 Months ago 61 views
Building a Basic Form with PySide6 Widgets and Handling User Input
7 Months ago 77 views
Mastering Django Framework: Building Scalable Web Applications
2 Months ago 27 views
What is Refactoring
7 Months ago 42 views
Spinn Code Team
About | Home
Contact: info@spinncode.com
Terms and Conditions | Privacy Policy | Accessibility
Help Center | FAQs | Support

© 2025 Spinn Company™. All rights reserved.
image