KRatingWidget Class

Displays a rating value as a row of pixmaps. More...

Header: #include <KRatingWidget>
CMake: find_package(KF6 REQUIRED COMPONENTS WidgetsAddons)
target_link_libraries(mytarget PRIVATE KF6::WidgetsAddons)
Inherits: QFrame

Properties

Public Functions

KRatingWidget(QWidget *parent = nullptr)
Qt::Alignment alignment() const
bool halfStepsEnabled() const
QIcon icon() const
Qt::LayoutDirection layoutDirection() const
int maxRating() const
int rating() const
int spacing() const

Public Slots

void setAlignment(Qt::Alignment align)
void setCustomPixmap(const QPixmap &pixmap)
void setHalfStepsEnabled(bool enabled)
void setIcon(const QIcon &icon)
void setLayoutDirection(Qt::LayoutDirection direction)
void setMaxRating(int max)
void setPixmapSize(int size)
void setRating(int rating)
void setSpacing(int)

Signals

void ratingChanged(int rating)

Detailed Description

The KRatingWidget displays a range of stars or other arbitrary pixmaps and allows the user to select a certain number by mouse.

See also KRatingPainter.

Property Documentation

alignment : Qt::Alignment

Access functions:

Qt::Alignment alignment() const
void setAlignment(Qt::Alignment align)

halfStepsEnabled : bool

Access functions:

bool halfStepsEnabled() const
void setHalfStepsEnabled(bool enabled)

icon : QIcon

Access functions:

QIcon icon() const
void setIcon(const QIcon &icon)

maxRating : int

Access functions:

int maxRating() const
void setMaxRating(int max)

rating : int

Access functions:

int rating() const
void setRating(int rating)

spacing : int

Access functions:

int spacing() const
void setSpacing(int)

Member Function Documentation

[explicit] KRatingWidget::KRatingWidget(QWidget *parent = nullptr)

Creates a new rating widget.

Qt::Alignment KRatingWidget::alignment() const

The alignment of the stars.

Note: Getter function for property alignment.

See also setAlignment.

bool KRatingWidget::halfStepsEnabled() const

If half steps are enabled one star equals to 2 rating points and uneven rating values result in half-stars being drawn.

Note: Getter function for property halfStepsEnabled.

See also setHalfStepsEnabled.

QIcon KRatingWidget::icon() const

The icon used to draw a star. In case a custom pixmap has been set this value is ignored.

Note: Getter function for property icon.

See also setIcon and setCustomPixmap.

Qt::LayoutDirection KRatingWidget::layoutDirection() const

The layout direction.

If RTL the stars representing the rating value will be drawn from the right.

See also setLayoutDirection.

int KRatingWidget::maxRating() const

Returns the maximum possible rating.

Note: Getter function for property maxRating.

See also setMaxRating().

int KRatingWidget::rating() const

Returns the current rating.

Note: Getter function for property rating.

See also setRating().

[signal] void KRatingWidget::ratingChanged(int rating)

This signal is emitted when the rating is changed.

[slot] void KRatingWidget::setAlignment(Qt::Alignment align)

The alignment of the stars in the drawing rect. All alignment flags are supported.

Note: Setter function for property alignment.

See also alignment().

[slot] void KRatingWidget::setCustomPixmap(const QPixmap &pixmap)

Set a custom pixmap.

[slot] void KRatingWidget::setHalfStepsEnabled(bool enabled)

If half steps are enabled (the default) then one rating step corresponds to half a star.

Note: Setter function for property halfStepsEnabled.

See also halfStepsEnabled().

[slot] void KRatingWidget::setIcon(const QIcon &icon)

Set a custom icon. Defaults to "rating".

Note: Setter function for property icon.

See also icon().

[slot] void KRatingWidget::setLayoutDirection(Qt::LayoutDirection direction)

LTR or RTL

See also layoutDirection().

[slot] void KRatingWidget::setMaxRating(int max)

Set the maximum allowed rating value. The default is 10 which means that a rating from 1 to 10 is selectable. If max is uneven steps are automatically only allowed full.

Note: Setter function for property maxRating.

See also maxRating().

[slot] void KRatingWidget::setPixmapSize(int size)

Set the recommended size of the pixmaps. This is only used for the sizeHint. The actual size is always dependent on the size of the widget itself.

[slot] void KRatingWidget::setRating(int rating)

Set the current rating. Calling this method will trigger the ratingChanged signal if rating is different from the previous rating.

Note: Setter function for property rating.

See also rating().

[slot] void KRatingWidget::setSpacing(int)

Set the spacing between the pixmaps. The default is 0.

Note: Setter function for property spacing.

See also spacing().

int KRatingWidget::spacing() const

The spacing between the rating stars.

Note: Getter function for property spacing.

See also setSpacing.