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.

focusInEvent

Repaint to show the focus indicator.

focusOutEvent

Repaint to hide the focus indicator.

get_rating

Return the current rating.

keyPressEvent

Adjust the rating from the keyboard.

leaveEvent

Handle mouse leave to clear hover.

mouseMoveEvent

Handle mouse move for hover preview.

mousePressEvent

Handle mouse click to set rating.

paintEvent

Paint a focus indicator under the star labels when focused.

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.

Methods:
clear_rating
clear_rating() -> None

Clear the rating (set to 0).

enterEvent
enterEvent(event) -> None

Handle mouse enter.

focusInEvent
focusInEvent(event) -> None

Repaint to show the focus indicator.

focusOutEvent
focusOutEvent(event) -> None

Repaint to hide the focus indicator.

get_rating
get_rating() -> float

Return the current rating.

keyPressEvent
keyPressEvent(event: QKeyEvent) -> None

Adjust the rating from the keyboard.

Left/Down decrease, Right/Up increase (by 0.5 when half stars are allowed), digit keys set the rating directly, Home/End jump to the extremes, and Delete/Backspace clear it.

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.

paintEvent
paintEvent(event) -> None

Paint a focus indicator under the star labels when focused.

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