KFileItemDelegate

KDE 4.7 PyKDE API Reference

- KDE's Python API

# KFileItemDelegate Class Reference

`from PyKDE4.kio import *`

Inherits: QAbstractItemDelegate → QObject

## Detailed Description

KFileItemDelegate is intended to be used to provide a KDE file system view, when using one of the standard item views in Qt with KDirModel.

While primarily intended to be used with KDirModel, it uses Qt.DecorationRole and Qt.DisplayRole for the icons and text labels, just like QItemDelegate, and can thus be used with any standard model.

When used with KDirModel however, KFileItemDelegate can change the way the display and/or decoration roles are drawn, based on properties of the file items. For example, if the file item is a symbolic link, it will use an italic font to draw the file name.

KFileItemDelegate also supports showing additional information about the file items below the icon labels.

Which information should be shown, if any, is controlled by the information property, which is a list that can be set by calling setShowInformation(), and read by calling showInformation(). By default this list is empty.

To use KFileItemDelegate, instantiate an object from the delegate, and call setItemDelegate() in one of the standard item views in Qt:

     QListView *listview = new QListView(this);
     KFileItemDelegate *delegate = new KFileItemDelegate(this);
     listview->setItemDelegate(delegate);

## Enumerations
Information | { NoInformation, Size, Permissions, OctalPermissions, Owner, OwnerAndGroup, CreationTime, ModificationTime, AccessTime, MimeType, FriendlyMimeType, LinkDest, LocalPathOrUrl, Comment }
## Methods
| __init__ (self, QObject parent=0)
| __init__ (self, KFileItemDelegate a0)
QWidget | createEditor (self, QWidget parent, QStyleOptionViewItem option, QModelIndex index)
bool | editorEvent (self, QEvent event, QAbstractItemModel model, QStyleOptionViewItem option, QModelIndex index)
bool | eventFilter (self, QObject object, QEvent event)
bool | helpEvent (self, QHelpEvent event, QAbstractItemView view, QStyleOptionViewItem option, QModelIndex index)
QRect | iconRect (self, QStyleOptionViewItem option, QModelIndex index)
bool | jobTransfersVisible (self)
QSize | maximumSize (self)
| paint (self, QPainter painter, QStyleOptionViewItem option, QModelIndex index)
| setEditorData (self, QWidget editor, QModelIndex index)
| setJobTransfersVisible (self, bool jobTransfersVisible)
| setMaximumSize (self, QSize size)
| setModelData (self, QWidget editor, QAbstractItemModel model, QModelIndex index)
| setShadowBlur (self, float radius)
| setShadowColor (self, QColor color)
| setShadowOffset (self, QPointF offset)
| setShowInformation (self, KFileItemDelegate.Information information)
| setShowToolTipWhenElided (self, bool showToolTip)
| setWrapMode (self, QTextOption::WrapMode wrapMode)
float | shadowBlur (self)
QColor | shadowColor (self)
QPointF | shadowOffset (self)
QRegion | shape (self, QStyleOptionViewItem option, QModelIndex index)
bool | showToolTipWhenElided (self)
QSize | sizeHint (self, QStyleOptionViewItem option, QModelIndex index)
| updateEditorGeometry (self, QWidget editor, QStyleOptionViewItem option, QModelIndex index)
QTextOption::WrapMode | wrapMode (self)

## Method Documentation

__init__ | ( | self, |
|  | QObject | parent=0
| ) |  |  |

Constructs a new KFileItemDelegate.

Parameters:

  | parent | The parent object for the delegate.

__init__ | ( | self, |
|  | KFileItemDelegate | a0
| ) |  |  |

QWidget createEditor | ( | self, |
|  | QWidget | parent,
|  | QStyleOptionViewItem | option,
|  | QModelIndex | index
| ) |  |  |

Reimplemented from QAbstractItemDelegate.

bool editorEvent | ( | self, |
|  | QEvent | event,
|  | QAbstractItemModel | model,
|  | QStyleOptionViewItem | option,
|  | QModelIndex | index
| ) |  |  |

Reimplemented from QAbstractItemDelegate.

bool eventFilter | ( | self, |
|  | QObject | object,
|  | QEvent | event
| ) |  |  |

Reimplemented from QAbstractItemDelegate.

bool helpEvent | ( | self, |
|  | QHelpEvent | event,
|  | QAbstractItemView | view,
|  | QStyleOptionViewItem | option,
|  | QModelIndex | index
| ) |  |  |

Reimplemented from QAbstractItemDelegate.

QRect iconRect | ( | self, |
|  | QStyleOptionViewItem | option,
|  | QModelIndex | index
| ) |  |  |

Returns the rectangle of the icon that is aligned inside the decoration rectangle.

Since:
  4.4

bool jobTransfersVisible | ( |  | self ) |

Returns whether or not the displaying of job transfers is enabled.

See also:
  setJobTransfersVisible()

Since:
  4.5

QSize maximumSize | ( |  | self ) |

Returns the maximum size for KFileItemDelegate.sizeHint().

See also:
  setMaximumSize()

Since:
  4.1

paint | ( | self, |
|  | QPainter | painter,
|  | QStyleOptionViewItem | option,
|  | QModelIndex | index
| ) |  |  |

Paints the item indicated by index, using painter.

The item will be drawn in the rectangle specified by option.rect. The correct size for that rectangle can be obtained by calling sizeHint().

This function will use the following data values if the model provides them for the item, in place of the values in option:

- Qt.FontRole The font that should be used for the display role.
- Qt.AlignmentRole The alignment of the display role.
- Qt.ForegroundRole The text color for the display role.
- Qt.BackgroundRole The background color for the item.

This function is reimplemented from QAbstractItemDelegate.

Parameters:

  | painter | The painter with which to draw the item.
  | option | The style options that should be used when painting the item.
  | index | The index to the item that should be painted.

setEditorData | ( | self, |
|  | QWidget | editor,
|  | QModelIndex | index
| ) |  |  |

Reimplemented from QAbstractItemDelegate.

setJobTransfersVisible | ( | self, |
|  | bool | jobTransfersVisible
| ) |  |  |

Enable/Disable the displaying of an animated overlay that is shown for any destination urls (in the view). When enabled, the animations (if any) will be drawn automatically.

Only the files/folders that are visible and have jobs associated with them will display the animation. You would likely not want this enabled if you perform some kind of custom painting that takes up a whole item, and will just make this(and what you paint) look funky.

Default is disabled.

Note: The model (KDirModel) needs to have it's method called with the same value, when you make the call to this method.

Since:
  4.5

setMaximumSize | ( | self, |
|  | QSize | size
| ) |  |  |

Sets the maximum size for KFileItemDelegate.sizeHint().

See also:
  maximumSize()

Since:
  4.1

setModelData | ( | self, |
|  | QWidget | editor,
|  | QAbstractItemModel | model,
|  | QModelIndex | index
| ) |  |  |

Reimplemented from QAbstractItemDelegate.

setShadowBlur | ( | self, |
|  | float | radius
| ) |  |  |

Sets the blur radius for the text shadow.

See also:
  shadowBlur()

setShadowColor | ( | self, |
|  | QColor | color
| ) |  |  |

Sets the color used for drawing the text shadow.

To enable text shadows, set the shadow color to a non-transparent color. To disable text shadows, set the color to Qt.transparent.

See also:
  shadowColor()

setShadowOffset | ( | self, |
|  | QPointF | offset
| ) |  |  |

Sets the horizontal and vertical offset for the text shadow.

See also:
  shadowOffset()

setShowInformation | ( | self, |
|  | KFileItemDelegate.Information | information
| ) |  |  |

Sets a single information line that is shown below the icon label in list views.

This is a convenience function for when you only want to show a single line of information.

Parameters:

  | information | The information that should be shown

setShowToolTipWhenElided | ( | self, |
|  | bool | showToolTip
| ) |  |  |

Sets whether a tooltip should be shown if the display role is elided containing the full display role information.

Note:
  The tooltip will only be shown if the Qt.ToolTipRole differs from Qt.DisplayRole, or if they match, showToolTipWhenElided flag is set and the display role information is elided.

See also:
  showToolTipWhenElided()

Since:
  4.2

setWrapMode | ( | self, |
|  | QTextOption::WrapMode | wrapMode
| ) |  |  |

When the contents text needs to be wrapped, wrapMode strategy will be followed.

Since:
  4.4

float shadowBlur | ( |  | self ) |

Returns the blur radius for the text shadow.

See also:
  setShadowBlur()

QColor shadowColor | ( |  | self ) |

Returns the color used for the text shadow.

See also:
  setShadowColor()

QPointF shadowOffset | ( |  | self ) |

Returns the offset used for the text shadow.

See also:
  setShadowOffset()

QRegion shape | ( | self, |
|  | QStyleOptionViewItem | option,
|  | QModelIndex | index
| ) |  |  |

Returns the shape of the item as a region. The returned region can be used for precise hit testing of the item.

bool showToolTipWhenElided | ( |  | self ) |

Returns whether a tooltip should be shown if the display role is elided containing the full display role information.

Note:
  The tooltip will only be shown if the Qt.ToolTipRole differs from Qt.DisplayRole, or if they match, showToolTipWhenElided flag is set and the display role information is elided.

See also:
  setShowToolTipWhenElided()

Since:
  4.2

QSize sizeHint | ( | self, |
|  | QStyleOptionViewItem | option,
|  | QModelIndex | index
| ) |  |  |

Returns the nominal size for the item referred to by index, given the provided options.

If the model provides a valid Qt.FontRole and/or Qt.AlignmentRole for the item, those will be used instead of the ones specified in the style options.

This function is reimplemented from QAbstractItemDelegate.

Parameters:

  | option | The style options that should be used when painting the item.
  | index | The index to the item for which to return the size hint.

updateEditorGeometry | ( | self, |
|  | QWidget | editor,
|  | QStyleOptionViewItem | option,
|  | QModelIndex | index
| ) |  |  |

Reimplemented from QAbstractItemDelegate.

QTextOption::WrapMode wrapMode | ( |  | self ) |

Returns the wrapping strategy followed to show text when it needs wrapping.

Since:
  4.4

## Enumeration Documentation

Information

This enum defines the additional information that can be displayed below item labels in icon views.

The information will only be shown for indexes for which the model provides a valid value for KDirModel.FileItemRole, and only when there's sufficient vertical space to display at least one line of the information, along with the display label.

For the number of items to be shown for folders, the model must provide a valid value for KDirMode.ChildCountRole, in addition to KDirModel.FileItemRole.

Note that KFileItemDelegate will not call KFileItem.determineMimeType() if KFileItem.isMimeTypeKnown() returns false, so if you want to display mime types you should use a KMimeTypeResolver with the model and the view, to ensure that mime types are resolved. If the mime type isn't known, "Unknown" will be displayed until the mime type has been successfully resolved.

See also:
  setShowInformation()

See also:
  showInformation()

See also:
  information

Enumerator:

  NoInformation |
  Size |
  Permissions |
  OctalPermissions |
  Owner |
  OwnerAndGroup |
  CreationTime |
  ModificationTime |
  AccessTime |
  MimeType |
  FriendlyMimeType |
  LinkDest |
  LocalPathOrUrl |
  Comment |