EqualizerBar

Visualize audio frequency changes with a custom Qt widget
Heads up! You've already completed this tutorial.

This custom PyQt5/PySide2-compatible widget provides a graphic equalizer frequency visualizer for audio applications built with Python. It is completely configurable — from the number of bars, the number of segments, and colors to the animated decay effect. It's ready to drop into your Python Qt applications.

The download package includes a demo animation using random data and some custom color configuration so you can explore how the equalizer widget works.

Basic setup

To create an EqualizerBar object, pass in the number of bars and the number of segments per bar.

python
equalizer = Equalizer(5, 10)

The default appearance of the PyQt5 equalizer bar widget. The default appearance of the equalizer bar widget.

The default range for each of the equalizer bars is 0...100. This can be adjusted using .setRange.

python
equalizer.setRange(0, 1000)

Configuring the decay animation

The equalizer bar includes a decay animation where peaks of values slowly fade over time. This is created by gradually subtracting a set value from the current value of each bar, using a recurring timer. If you're interested in other types of animations in Qt, see the tutorial on animated widgets and QPropertyAnimation.

The frequency of the decay timer (in milliseconds) can be configured using .setDecayFrequencyMs. The default value is 100ms.

python
equalizer.setDecayFrequencyMs()

Passing 0 will disable the decay mechanism.

On each tick a set value is removed from the current value of each bar. This is configured by using .setDecay. Adjust this based on your equalizer's range of possible values.

PyQt/PySide Office Hours 1:1 with Martin Fitzpatrick — Save yourself time and frustration. Get one on one help with your projects. Bring issues, bugs and questions about usability to architecture and maintainability, and leave with solutions.

60 mins ($195)

python
equalizer.setDecay(0, 1000)

Customizing bar style and colors

The number of bars to display and the number of segments in the bars/the colors of those bars are defined at startup.

python
equalizer = EqualizerBar(10,  ["#2d004b", "#542788", "#8073ac", "#b2abd2", "#d8daeb", "#f7f7f7", "#fee0b6", "#fdb863", "#e08214", "#b35806", "#7f3b08"])

Purple Orange theme equalizer with 10 bars Purple Orange theme with 10 bars

To set the colors after startup, either provide a list of colors (QColor or hex values) at startup, or use the .setColors method. Passing a list of colors to this method will change the number of segments to match the colors provided.

python
equalizer.setColors(["#810f7c", "#8856a7", "#8c96c6", "#b3cde3", "#edf8fb"])

You can also use .setColor to set a single color for all segments, without changing the number of bars.

python
equalizer.setColor('red')

Adjusting bar padding and segment sizing

The spacing around the equalizer graphic is configured with .setBarPadding providing an integer value to add in pixels.

python
equalizer.setBarPadding(20)

The proportion of each segment in the bar which is solid/empty is configured using .setBarSolidXPercent or .setBarSolidYPercent with a float value between 0...1. This can be used to make bar segments thinner and narrower if you prefer.

python
equalizer.setBarSolidXPercent(0.4)
equalizer.setBarSolidYPercent(0.4)

Finally, the background color can be configured using .setBackgroundColor.

python
equalizer.setBackgroundColor('#0D1F2D')

Customizing equalizer bar padding and segment sizing in PyQt5. Customizing bar padding and sizing.

If you want to learn more about building your own custom widgets in PyQt5 or PySide2, take a look at the creating your own custom widgets tutorial. You might also be interested in other custom widgets like the Gradient widget or the Palette widget.

The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

EqualizerBar was written by Martin Fitzpatrick.

Martin Fitzpatrick is the creator of Python GUIs, and has been developing Python/Qt applications for the past 12+ years. He has written a number of popular Python books and provides Python software development & consulting for teams and startups.