KRatingPainter

KDE 4.2 PyKDE API Reference

- KDE's Python API

# KRatingPainter Class Reference

`from PyKDE4.nepomuk import *`

## Detailed Description

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
| __init__ (self)
| __init__ (self, KRatingPainter other)
Qt.Alignment | alignment (self)
QPixmap | customPixmap (self)
bool | halfStepsEnabled (self)
QIcon | icon (self)
bool | isEnabled (self)
Qt.LayoutDirection | layoutDirection (self)
int | maxRating (self)
| paint (self, QPainter painter, QRect rect, int rating, int hoverRating=-1)
int | ratingFromPosition (self, QRect rect, QPoint pos)
| setAlignment (self, Qt.Alignment align)
| setCustomPixmap (self, QPixmap pixmap)
| setEnabled (self, bool enabled)
| setHalfStepsEnabled (self, bool enabled)
| setIcon (self, QIcon icon)
| setLayoutDirection (self, Qt.LayoutDirection direction)
| setMaxRating (self, int max)
| setSpacing (self, int spacing)
int | spacing (self)
## Static Methods
int | getRatingFromPosition (QRect rect, Qt.Alignment align, Qt.LayoutDirection direction, QPoint pos)
| paintRating (QPainter p, QRect rect, Qt.Alignment align, int rating, int hoverRating=-1)

## Method Documentation

__init__ | ( |  | self ) |

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

__init__ | ( | self, |
|  | KRatingPainter | other
| ) |  |  |

Qt.Alignment alignment | ( |  | self ) |

The alignment of the stars.

\sa setAlignment

QPixmap customPixmap | ( |  | self ) |

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

\sa setCustomPixmap

int getRatingFromPosition | ( | QRect | rect,
|  | Qt.Alignment | align,
|  | Qt.LayoutDirection | direction,
|  | QPoint | pos
| ) |  |  |

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.

bool halfStepsEnabled | ( |  | self ) |

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

\sa setHalfStepsEnabled

QIcon icon | ( |  | self ) |

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

\sa setIcon, setCustomPixmap

bool isEnabled | ( |  | self ) |

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

\sa setEnabled

Qt.LayoutDirection layoutDirection | ( |  | self ) |

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

\sa setLayoutDirection

int maxRating | ( |  | self ) |

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

\sa setMaxRating

paint | ( | self, |
|  | QPainter | painter,
|  | QRect | rect,
|  | int | rating,
|  | int | hoverRating=-1
| ) |  |  |

Draw the rating.

Parameters:

  | painter | The painter to draw the rating to.

Parameters:

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

Parameters:

  | rating | The actual rating value to draw.

Parameters:

  | 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 | ( | QPainter | p,
|  | QRect | rect,
|  | Qt.Alignment | align,
|  | int | rating,
|  | int | hoverRating=-1
| ) |  |  |

Convenience method that paints a rating into the given rect.

LayoutDirection is read from QPainter.

Parameters:

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

int ratingFromPosition | ( | self, |
|  | QRect | rect,
|  | QPoint | pos
| ) |  |  |

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 | ( | self, |
|  | Qt.Alignment | align
| ) |  |  |

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

setCustomPixmap | ( | self, |
|  | QPixmap | pixmap
| ) |  |  |

Set a custom pixmap.

setEnabled | ( | self, |
|  | bool | enabled
| ) |  |  |

Enable or disable the rating. Default is enabled.

setHalfStepsEnabled | ( | self, |
|  | bool | enabled
| ) |  |  |

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

setIcon | ( | self, |
|  | QIcon | icon
| ) |  |  |

Set a custom icon. Defaults to "rating".

setLayoutDirection | ( | self, |
|  | Qt.LayoutDirection | direction
| ) |  |  |

LTR or RTL

setMaxRating | ( | self, |
|  | int | max
| ) |  |  |

The maximum rating. Defaults to 10.

setSpacing | ( | self, |
|  | int | spacing
| ) |  |  |

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

int spacing | ( |  | self ) |

The spacing between rating pixmaps.

\sa setSpacing