Skip to content

rating_widget

_rating_widget

Star/score rating widget.

Classes:

Name Description
FXRatingWidget

A clickable star rating widget.

Classes

FXRatingWidget

FXRatingWidget(
    parent: Optional[QWidget] = None,
    max_rating: int = 5,
    initial_rating: float = 0,
    allow_half: bool = False,
    icon_size: int = 20,
    filled_icon: str = "star",
    empty_icon: str = "star_border",
    half_icon: str = "star_half",
)

Bases: FXThemeAware, QWidget


              flowchart TD
              fxgui.fxwidgets._rating_widget.FXRatingWidget[FXRatingWidget]
              fxgui.fxstyle.FXThemeAware[FXThemeAware]

                              fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._rating_widget.FXRatingWidget
                


              click fxgui.fxwidgets._rating_widget.FXRatingWidget href "" "fxgui.fxwidgets._rating_widget.FXRatingWidget"
              click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
            

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.

Attributes
rating property writable
rating: float

Return the current rating.

Functions
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