Skip to content

Rating Widget

A star rating input widget for collecting user ratings.

Preview

FXRatingWidget

FXRatingWidget

Bases: FXThemeAware, QWidget

A clickable star rating widget.

This widget provides a configurable star rating with: - Configurable max stars - Half-star support (optional) - Hover preview - Theme-aware icons

Parameters:

Name Type Description Default

parent

Optional[QWidget]

Parent widget.

None

max_rating

int

Maximum number of stars.

5

initial_rating

float

Initial rating value.

0

allow_half

bool

Whether to allow half-star ratings.

False

icon_size

int

Size of star icons in pixels.

20

filled_icon

str

Icon name for filled stars.

'star'

empty_icon

str

Icon name for empty stars.

'star_border'

half_icon

str

Icon name for half-filled stars.

'star_half'
Signals

rating_changed: Emitted when the rating changes.

Examples:

>>> rating = FXRatingWidget(max_rating=5, initial_rating=3)
>>> rating.rating_changed.connect(lambda r: print(f"Rating: {r}"))

Methods:

Name Description
clear_rating

Clear the rating (set to 0).

enterEvent

Handle mouse enter.

get_rating

Return the current rating.

leaveEvent

Handle mouse leave to clear hover.

mouseMoveEvent

Handle mouse move for hover preview.

mousePressEvent

Handle mouse click to set rating.

set_rating

Set the rating value.

Attributes:

Name Type Description
rating float

Return the current rating.

rating property writable

rating: float

Return the current rating.

clear_rating

clear_rating() -> None

Clear the rating (set to 0).

enterEvent

enterEvent(event) -> None

Handle mouse enter.

get_rating

get_rating() -> float

Return the current rating.

leaveEvent

leaveEvent(event) -> None

Handle mouse leave to clear hover.

mouseMoveEvent

mouseMoveEvent(event: QMouseEvent) -> None

Handle mouse move for hover preview.

mousePressEvent

mousePressEvent(event: QMouseEvent) -> None

Handle mouse click to set rating.

set_rating

set_rating(rating: float, emit: bool = True) -> None

Set the rating value.

Parameters:

Name Type Description Default

rating

float

The rating value (0 to max_rating).

required

emit

bool

Whether to emit the rating_changed signal.

True