[][src]Struct qt_widgets::QStyledItemDelegate

#[repr(C)]pub struct QStyledItemDelegate { /* fields omitted */ }

The QStyledItemDelegate class provides display and editing facilities for data items from a model.

C++ class: QStyledItemDelegate.

C++ documentation:

The QStyledItemDelegate class provides display and editing facilities for data items from a model.

When displaying data from models in Qt item views, e.g., a QTableView, the individual items are drawn by a delegate. Also, when an item is edited, it provides an editor widget, which is placed on top of the item view while editing takes place. QStyledItemDelegate is the default delegate for all Qt item views, and is installed upon them when they are created.

The QStyledItemDelegate class is one of the Model/View Classes and is part of Qt's model/view framework. The delegate allows the display and editing of items to be developed independently from the model and view.

The data of items in models are assigned an ItemDataRole; each item can store a QVariant for each role. QStyledItemDelegate implements display and editing for the most common datatypes expected by users, including booleans, integers, and strings.

The data will be drawn differently depending on which role they have in the model. The following table describes the roles and the data types the delegate can handle for each of them. It is often sufficient to ensure that the model returns appropriate data for each of the roles to determine the appearance of items in views.

Editors are created with a QItemEditorFactory; a default static instance provided by QItemEditorFactory is installed on all item delegates. You can set a custom factory using setItemEditorFactory() or set a new default factory with QItemEditorFactory::setDefaultFactory(). It is the data stored in the item model with the EditRole that is edited. See the QItemEditorFactory class for a more high-level introduction to item editor factories. The Color Editor Factory example shows how to create custom editors with a factory.

Methods

impl QStyledItemDelegate[src]

pub unsafe fn create_editor(
    &self,
    parent: impl CastInto<Ptr<QWidget>>,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
) -> QPtr<QWidget>
[src]

Reimplemented from QAbstractItemDelegate::createEditor().

Calls C++ function: virtual QWidget* QStyledItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemDelegate::createEditor().

Returns the widget used to edit the item specified by index for editing. The parent widget and style option are used to control how the editor widget appears.

See also QAbstractItemDelegate::createEditor().

pub unsafe fn display_text(
    &self,
    value: impl CastInto<Ref<QVariant>>,
    locale: impl CastInto<Ref<QLocale>>
) -> CppBox<QString>
[src]

This function returns the string that the delegate will use to display the Qt::DisplayRole of the model in locale. value is the value of the Qt::DisplayRole provided by the model.

Calls C++ function: virtual QString QStyledItemDelegate::displayText(const QVariant& value, const QLocale& locale) const.

C++ documentation:

This function returns the string that the delegate will use to display the Qt::DisplayRole of the model in locale. value is the value of the Qt::DisplayRole provided by the model.

The default implementation uses the QLocale::toString to convert value into a QString.

This function is not called for empty model indices, i.e., indices for which the model returns an invalid QVariant.

See also QAbstractItemModel::data().

pub unsafe fn item_editor_factory(&self) -> Ptr<QItemEditorFactory>[src]

Returns the editor factory used by the item delegate. If no editor factory is set, the function will return null.

Calls C++ function: QItemEditorFactory* QStyledItemDelegate::itemEditorFactory() const.

C++ documentation:

Returns the editor factory used by the item delegate. If no editor factory is set, the function will return null.

See also setItemEditorFactory().

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QStyledItemDelegate::metaObject() const.

pub unsafe fn new_1a(
    parent: impl CastInto<Ptr<QObject>>
) -> QBox<QStyledItemDelegate>
[src]

Constructs an item delegate with the given parent.

Calls C++ function: [constructor] void QStyledItemDelegate::QStyledItemDelegate(QObject* parent = …).

C++ documentation:

Constructs an item delegate with the given parent.

pub unsafe fn new_0a() -> QBox<QStyledItemDelegate>[src]

The QStyledItemDelegate class provides display and editing facilities for data items from a model.

Calls C++ function: [constructor] void QStyledItemDelegate::QStyledItemDelegate().

C++ documentation:

The QStyledItemDelegate class provides display and editing facilities for data items from a model.

When displaying data from models in Qt item views, e.g., a QTableView, the individual items are drawn by a delegate. Also, when an item is edited, it provides an editor widget, which is placed on top of the item view while editing takes place. QStyledItemDelegate is the default delegate for all Qt item views, and is installed upon them when they are created.

The QStyledItemDelegate class is one of the Model/View Classes and is part of Qt's model/view framework. The delegate allows the display and editing of items to be developed independently from the model and view.

The data of items in models are assigned an ItemDataRole; each item can store a QVariant for each role. QStyledItemDelegate implements display and editing for the most common datatypes expected by users, including booleans, integers, and strings.

The data will be drawn differently depending on which role they have in the model. The following table describes the roles and the data types the delegate can handle for each of them. It is often sufficient to ensure that the model returns appropriate data for each of the roles to determine the appearance of items in views.

Editors are created with a QItemEditorFactory; a default static instance provided by QItemEditorFactory is installed on all item delegates. You can set a custom factory using setItemEditorFactory() or set a new default factory with QItemEditorFactory::setDefaultFactory(). It is the data stored in the item model with the EditRole that is edited. See the QItemEditorFactory class for a more high-level introduction to item editor factories. The Color Editor Factory example shows how to create custom editors with a factory.

pub unsafe fn paint(
    &self,
    painter: impl CastInto<Ptr<QPainter>>,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

Reimplemented from QAbstractItemDelegate::paint().

Calls C++ function: virtual void QStyledItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemDelegate::paint().

Renders the delegate using the given painter and style option for the item specified by index.

This function paints the item using the view's QStyle.

When reimplementing paint in a subclass. Use the initStyleOption() to set up the option in the same way as the QStyledItemDelegate.

Whenever possible, use the option while painting. Especially its rect variable to decide where to draw and its state to determine if it is enabled or selected.

After painting, you should ensure that the painter is returned to the state it was supplied in when this function was called. For example, it may be useful to call QPainter::save() before painting and QPainter::restore() afterwards.

See also QItemDelegate::paint(), QStyle::drawControl(), and QStyle::CE_ItemViewItem.

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QStyledItemDelegate::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QStyledItemDelegate::qt_metacast(const char* arg1).

pub unsafe fn set_editor_data(
    &self,
    editor: impl CastInto<Ptr<QWidget>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

Reimplemented from QAbstractItemDelegate::setEditorData().

Calls C++ function: virtual void QStyledItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemDelegate::setEditorData().

Sets the data to be displayed and edited by the editor from the data model item specified by the model index.

The default implementation stores the data in the editor widget's user property.

See also QMetaProperty::isUser().

pub unsafe fn set_item_editor_factory(
    &self,
    factory: impl CastInto<Ptr<QItemEditorFactory>>
)
[src]

Sets the editor factory to be used by the item delegate to be the factory specified. If no editor factory is set, the item delegate will use the default editor factory.

Calls C++ function: void QStyledItemDelegate::setItemEditorFactory(QItemEditorFactory* factory).

C++ documentation:

Sets the editor factory to be used by the item delegate to be the factory specified. If no editor factory is set, the item delegate will use the default editor factory.

See also itemEditorFactory().

pub unsafe fn set_model_data(
    &self,
    editor: impl CastInto<Ptr<QWidget>>,
    model: impl CastInto<Ptr<QAbstractItemModel>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

Reimplemented from QAbstractItemDelegate::setModelData().

Calls C++ function: virtual void QStyledItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemDelegate::setModelData().

Gets data from the editor widget and stores it in the specified model at the item index.

The default implementation gets the value to be stored in the data model from the editor widget's user property.

See also QMetaProperty::isUser().

pub unsafe fn size_hint(
    &self,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
) -> CppBox<QSize>
[src]

Reimplemented from QAbstractItemDelegate::sizeHint().

Calls C++ function: virtual QSize QStyledItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemDelegate::sizeHint().

Returns the size needed by the delegate to display the item specified by index, taking into account the style information provided by option.

This function uses the view's QStyle to determine the size of the item.

See also QStyle::sizeFromContents() and QStyle::CT_ItemViewItem.

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn tr(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QStyledItemDelegate::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: *const c_char,
    c: *const c_char,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QStyledItemDelegate::trUtf8(const char* s, const char* c, int n).

pub unsafe fn update_editor_geometry(
    &self,
    editor: impl CastInto<Ptr<QWidget>>,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

Reimplemented from QAbstractItemDelegate::updateEditorGeometry().

Calls C++ function: virtual void QStyledItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const.

C++ documentation:

Reimplemented from QAbstractItemDelegate::updateEditorGeometry().

Updates the editor for the item specified by index according to the style option given.

Methods from Deref<Target = QAbstractItemDelegate>

pub fn commit_data(&self) -> Signal<(*mut QWidget,)>[src]

This signal must be emitted when the editor widget has completed editing the data, and wants to write it back into the model.

Returns a built-in Qt signal QAbstractItemDelegate::commitData that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal must be emitted when the editor widget has completed editing the data, and wants to write it back into the model.

pub fn close_editor(&self) -> Signal<(*mut QWidget, EndEditHint)>[src]

This signal is emitted when the user has finished editing an item using the specified editor.

Returns a built-in Qt signal QAbstractItemDelegate::closeEditor that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted when the user has finished editing an item using the specified editor.

The hint provides a way for the delegate to influence how the model and view behave after editing is completed. It indicates to these components what action should be performed next to provide a comfortable editing experience for the user. For example, if EditNextItem is specified, the view should use a delegate to open an editor on the next item in the model.

See also EndEditHint.

pub fn size_hint_changed(&self) -> Signal<(*const QModelIndex,)>[src]

This signal must be emitted when the sizeHint() of index changed.

Returns a built-in Qt signal QAbstractItemDelegate::sizeHintChanged that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal must be emitted when the sizeHint() of index changed.

Views automatically connect to this signal and relayout items as necessary.

This function was introduced in Qt 4.4.

pub unsafe fn create_editor(
    &self,
    parent: impl CastInto<Ptr<QWidget>>,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
) -> QPtr<QWidget>
[src]

Returns the editor to be used for editing the data item with the given index. Note that the index contains information about the model being used. The editor's parent widget is specified by parent, and the item options by option.

Calls C++ function: virtual QWidget* QAbstractItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const.

C++ documentation:

Returns the editor to be used for editing the data item with the given index. Note that the index contains information about the model being used. The editor's parent widget is specified by parent, and the item options by option.

The base implementation returns 0. If you want custom editing you will need to reimplement this function.

The returned editor widget should have Qt::StrongFocus; otherwise, QMouseEvents received by the widget will propagate to the view. The view's background will shine through unless the editor paints its own background (e.g., with setAutoFillBackground()).

See also destroyEditor(), setModelData(), and setEditorData().

pub unsafe fn destroy_editor(
    &self,
    editor: impl CastInto<Ptr<QWidget>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

Called when the editor is no longer needed for editing the data item with the given index and should be destroyed. The default behavior is a call to deleteLater on the editor. It is possible e.g. to avoid this delete by reimplementing this function.

Calls C++ function: virtual void QAbstractItemDelegate::destroyEditor(QWidget* editor, const QModelIndex& index) const.

C++ documentation:

Called when the editor is no longer needed for editing the data item with the given index and should be destroyed. The default behavior is a call to deleteLater on the editor. It is possible e.g. to avoid this delete by reimplementing this function.

This function was introduced in Qt 5.0.

See also createEditor().

pub unsafe fn editor_event(
    &self,
    event: impl CastInto<Ptr<QEvent>>,
    model: impl CastInto<Ptr<QAbstractItemModel>>,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

When editing of an item starts, this function is called with the event that triggered the editing, the model, the index of the item, and the option used for rendering the item.

Calls C++ function: virtual bool QAbstractItemDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index).

C++ documentation:

When editing of an item starts, this function is called with the event that triggered the editing, the model, the index of the item, and the option used for rendering the item.

Mouse events are sent to editorEvent() even if they don't start editing of the item. This can, for instance, be useful if you wish to open a context menu when the right mouse button is pressed on an item.

The base implementation returns false (indicating that it has not handled the event).

pub unsafe fn help_event(
    &self,
    event: impl CastInto<Ptr<QHelpEvent>>,
    view: impl CastInto<Ptr<QAbstractItemView>>,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
) -> bool
[src]

Whenever a help event occurs, this function is called with the event view option and the index that corresponds to the item where the event occurs.

Calls C++ function: virtual bool QAbstractItemDelegate::helpEvent(QHelpEvent* event, QAbstractItemView* view, const QStyleOptionViewItem& option, const QModelIndex& index).

C++ documentation:

Whenever a help event occurs, this function is called with the event view option and the index that corresponds to the item where the event occurs.

Returns true if the delegate can handle the event; otherwise returns false. A return value of true indicates that the data obtained using the index had the required role.

For QEvent::ToolTip and QEvent::WhatsThis events that were handled successfully, the relevant popup may be shown depending on the user's system configuration.

This function was introduced in Qt 4.3.

See also QHelpEvent.

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QAbstractItemDelegate::metaObject() const.

pub unsafe fn paint(
    &self,
    painter: impl CastInto<Ptr<QPainter>>,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

This pure abstract function must be reimplemented if you want to provide custom rendering. Use the painter and style option to render the item specified by the item index.

Calls C++ function: pure virtual void QAbstractItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const.

C++ documentation:

This pure abstract function must be reimplemented if you want to provide custom rendering. Use the painter and style option to render the item specified by the item index.

If you reimplement this you must also reimplement sizeHint().

pub unsafe fn painting_roles(&self) -> CppBox<QVectorOfInt>[src]

Calls C++ function: virtual QVector<int> QAbstractItemDelegate::paintingRoles() const.

pub unsafe fn qt_metacall(
    &self,
    arg1: Call,
    arg2: c_int,
    arg3: *mut *mut c_void
) -> c_int
[src]

Calls C++ function: virtual int QAbstractItemDelegate::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void[src]

Calls C++ function: virtual void* QAbstractItemDelegate::qt_metacast(const char* arg1).

pub unsafe fn set_editor_data(
    &self,
    editor: impl CastInto<Ptr<QWidget>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

Sets the contents of the given editor to the data for the item at the given index. Note that the index contains information about the model being used.

Calls C++ function: virtual void QAbstractItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const.

C++ documentation:

Sets the contents of the given editor to the data for the item at the given index. Note that the index contains information about the model being used.

The base implementation does nothing. If you want custom editing you will need to reimplement this function.

See also setModelData().

pub unsafe fn set_model_data(
    &self,
    editor: impl CastInto<Ptr<QWidget>>,
    model: impl CastInto<Ptr<QAbstractItemModel>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

Sets the data for the item at the given index in the model to the contents of the given editor.

Calls C++ function: virtual void QAbstractItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const.

C++ documentation:

Sets the data for the item at the given index in the model to the contents of the given editor.

The base implementation does nothing. If you want custom editing you will need to reimplement this function.

See also setEditorData().

pub unsafe fn size_hint(
    &self,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
) -> CppBox<QSize>
[src]

This pure abstract function must be reimplemented if you want to provide custom rendering. The options are specified by option and the model item by index.

Calls C++ function: pure virtual QSize QAbstractItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const.

C++ documentation:

This pure abstract function must be reimplemented if you want to provide custom rendering. The options are specified by option and the model item by index.

If you reimplement this you must also reimplement paint().

pub unsafe fn update_editor_geometry(
    &self,
    editor: impl CastInto<Ptr<QWidget>>,
    option: impl CastInto<Ref<QStyleOptionViewItem>>,
    index: impl CastInto<Ref<QModelIndex>>
)
[src]

Updates the geometry of the editor for the item with the given index, according to the rectangle specified in the option. If the item has an internal layout, the editor will be laid out accordingly. Note that the index contains information about the model being used.

Calls C++ function: virtual void QAbstractItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const.

C++ documentation:

Updates the geometry of the editor for the item with the given index, according to the rectangle specified in the option. If the item has an internal layout, the editor will be laid out accordingly. Note that the index contains information about the model being used.

The base implementation does nothing. If you want custom editing you must reimplement this function.

Trait Implementations

impl CppDeletable for QStyledItemDelegate[src]

unsafe fn delete(&self)[src]

Destroys the item delegate.

Calls C++ function: virtual [destructor] void QStyledItemDelegate::~QStyledItemDelegate().

C++ documentation:

Destroys the item delegate.

impl Deref for QStyledItemDelegate[src]

type Target = QAbstractItemDelegate

The resulting type after dereferencing.

fn deref(&self) -> &QAbstractItemDelegate[src]

Calls C++ function: QAbstractItemDelegate* static_cast<QAbstractItemDelegate*>(QStyledItemDelegate* ptr).

impl DynamicCast<QStyledItemDelegate> for QAbstractItemDelegate[src]

unsafe fn dynamic_cast(
    ptr: Ptr<QAbstractItemDelegate>
) -> Ptr<QStyledItemDelegate>
[src]

Calls C++ function: QStyledItemDelegate* dynamic_cast<QStyledItemDelegate*>(QAbstractItemDelegate* ptr).

impl DynamicCast<QStyledItemDelegate> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QStyledItemDelegate>[src]

Calls C++ function: QStyledItemDelegate* dynamic_cast<QStyledItemDelegate*>(QObject* ptr).

impl StaticDowncast<QStyledItemDelegate> for QAbstractItemDelegate[src]

unsafe fn static_downcast(
    ptr: Ptr<QAbstractItemDelegate>
) -> Ptr<QStyledItemDelegate>
[src]

Calls C++ function: QStyledItemDelegate* static_cast<QStyledItemDelegate*>(QAbstractItemDelegate* ptr).

impl StaticDowncast<QStyledItemDelegate> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QStyledItemDelegate>[src]

Calls C++ function: QStyledItemDelegate* static_cast<QStyledItemDelegate*>(QObject* ptr).

impl StaticUpcast<QAbstractItemDelegate> for QStyledItemDelegate[src]

unsafe fn static_upcast(
    ptr: Ptr<QStyledItemDelegate>
) -> Ptr<QAbstractItemDelegate>
[src]

Calls C++ function: QAbstractItemDelegate* static_cast<QAbstractItemDelegate*>(QStyledItemDelegate* ptr).

impl StaticUpcast<QObject> for QStyledItemDelegate[src]

unsafe fn static_upcast(ptr: Ptr<QStyledItemDelegate>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QStyledItemDelegate* ptr).

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.