# class KRatingPainter

###

Module | nepomuk
Namespace |
Class | KRatingPainter
Inherits |

Utility class that draws a row of stars for a rating value.

The KRatingPainter also allows to determine a rating value from a position in the draw area. it supports all different alignments and custom icons.

For showing a rating in a widget see KRatingWidget.

Author Sebastian Trueg <trueg@kde.org>

\since 4.1

### methods

- KRatingPainter ( )

  returns ctor

  Create a new KRatingPainter. For most cases the static methods paintRating and getRatingFromPosition should be sufficient.

- alignment ( )

  returns Qt.Alignment

  The alignment of the stars.

  See also setAlignment

- customPixmap ( )

  returns QPixmap

  The custom pixmap set to draw a star. If no custom pixmap has been set, an invalid pixmap is returned.

  See also setCustomPixmap

- getRatingFromPosition (rect, align, direction, pos)

  returns int
  static

  Argument | Type | Default
  --- | --- | ---
  rect | QRect |
  align | Qt.Alignment |
  direction | Qt.LayoutDirection |
  pos | QPoint |

  Get the rating that would be selected if the user clicked position pos within rect if the rating has been drawn with paintRating() using the same rect and align values.

  Returns The new rating or -1 if pos is outside of the rating area.

- halfStepsEnabled ( )

  returns bool

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

  See also setHalfStepsEnabled

- icon ( )

  returns QIcon

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

  See also setIcon, setCustomPixmap

- isEnabled ( )

  returns bool

  The rating can be painted in a disabled state where no color is used and hover ratings are ignored.

  See also setEnabled

- layoutDirection ( )

  returns Qt.LayoutDirection

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

  See also setLayoutDirection

- maxRating ( )

  returns int

  The maximum rating, i.e. how many stars are drawn in total.

  See also setMaxRating

- paint (painter, rect, rating, hoverRating)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  painter | QPainter |
  rect | QRect |
  rating | int |
  hoverRating | int | -1

  Draw the rating.

  painter - The painter to draw the rating to.

  rect - The geometry of the rating. The alignment of the rating is used relative to this value.

  rating - The actual rating value to draw.

  hoverRating - The hover rating indicates the position the user hovers the mouse pointer at. This will provide visual feedback about the new rating if the user would actually click as well as the difference to the current rating.

- paintRating (p, rect, align, rating, hoverRating)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  p | QPainter |
  rect | QRect |
  align | Qt.Alignment |
  rating | int |
  hoverRating | int | -1

  Convenience method that paints a rating into the given rect.

  LayoutDirection is read from QPainter.

  align - can be aligned vertically and horizontally. Using Qt.AlignJustify will insert spacing between the stars.

- ratingFromPosition (rect, pos)

  returns int

  Argument | Type | Default
  --- | --- | ---
  rect | QRect |
  pos | QPoint |

  Calculate the rating value from mouse position pos.

  Returns The rating corresponding to pos or -1 if pos is outside of the configured rect.

- setAlignment (align)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  align | Qt.Alignment |

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

- setCustomPixmap (pixmap)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  pixmap | QPixmap |

  Set a custom pixmap.

- setEnabled (enabled)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  enabled | bool |

  Enable or disable the rating. Default is enabled.

- setHalfStepsEnabled (enabled)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  enabled | bool |

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

- setIcon (icon)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  icon | QIcon |

  Set a custom icon. Defaults to "rating".

- setLayoutDirection (direction)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  direction | Qt.LayoutDirection |

  LTR or RTL

- setMaxRating (max)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  max | int |

  The maximum rating. Defaults to 10.

- setSpacing (spacing)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  spacing | int |

  Set the spacing between rating pixmaps. Be aware that for justified horizontal alignment this values may be ignored.

- spacing ( )

  returns int

  The spacing between rating pixmaps.

  See also setSpacing