Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtGui.QAbstractItemDelegate Class Referenceabstract

The QAbstractItemDelegate class is used to display and edit data items from a model. More...

Inheritance diagram for QtGui.QAbstractItemDelegate:
Collaboration diagram for QtGui.QAbstractItemDelegate:

Public Types

enum  EndEditHint {
  EditNextItem = 1, EditPreviousItem = 2, NoHint = 0, RevertModelCache = 4,
  SubmitModelCache = 3
}
  More...
 

Public Member Functions

 QAbstractItemDelegate (QObject parent=null)
 
 
override void CreateProxy ()
 
virtual QWidget CreateEditor (QWidget parent, QStyleOptionViewItem option, QModelIndex index)
 
 
virtual bool OnEditorEvent (QEvent @event, QAbstractItemModel model, QStyleOptionViewItem option, QModelIndex index)
 
 
new bool OnHelpEvent (QHelpEvent @event, QAbstractItemView view, QStyleOptionViewItem option, QModelIndex index)
 
 
abstract void Paint (QPainter painter, QStyleOptionViewItem option, QModelIndex index)
 
 
virtual void SetEditorData (QWidget editor, QModelIndex index)
 
 
virtual void SetModelData (QWidget editor, QAbstractItemModel model, QModelIndex index)
 
 
abstract QSize SizeHint (QStyleOptionViewItem option, QModelIndex index)
 
 
virtual void UpdateEditorGeometry (QWidget editor, QStyleOptionViewItem option, QModelIndex index)
 
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.QObject
 QObject (QObject parent=null)
 
 
new bool BlockSignals (bool b)
 
 
new
System.Collections.Generic.List
< QObject
Children ()
 
 
new bool Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
new void DeleteLater ()
 
 
new bool Disconnect (QObject receiver, string member=null)
 
 
new bool Disconnect (string signal=null, QObject receiver=null, string member=null)
 
 
new void DumpObjectInfo ()
 
 
new void DumpObjectTree ()
 
 
new
System.Collections.Generic.List
< QByteArray
DynamicPropertyNames ()
 
 
virtual bool OnEvent (QEvent arg1)
 
 
virtual bool EventFilter (QObject arg1, QEvent arg2)
 
 
new bool Inherits (string classname)
 
 
new void InstallEventFilter (QObject arg1)
 
 
new bool IsWidgetType ()
 
 
new void KillTimer (int id)
 
 
new object Property (string name)
 
 
new void RemoveEventFilter (QObject arg1)
 
 
new bool SetProperty (string name, object value)
 
 
new void SetUserData (uint id, QObjectUserData data)
 
new bool SignalsBlocked ()
 
 
new int StartTimer (int interval)
 
 
new QObjectUserData UserData (uint id)
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.Qt
delegate QTextStream FuncQTextStreamQTextStream (QTextStream qTextStream)
 
delegate string FuncStringQByteArray (QByteArray qByteArray)
 
delegate QByteArray FuncQByteArrayString (string @string)
 
delegate void ActionQtMsgTypeString (QtMsgType qtMsgType, string @string)
 
delegate QObject FuncQObject ()
 

Static Public Member Functions

static string ElidedText (QFontMetrics fontMetrics, int width, Qt.TextElideMode mode, string text)
 
 
static string Tr (string s, string c=null)
 
static string Tr (string s, string c, int n)
 
static string TrUtf8 (string s, string c=null)
 
static string TrUtf8 (string s, string c, int n)
 
- Static Public Member Functions inherited from QtCore.QObject
static bool Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
static bool Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection)
 
 
static bool Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member)
 
 
static bool Disconnect (QObject sender, string signal, QObject receiver, string member)
 
 
static uint RegisterUserData ()
 
static string Tr (string s, string c=null)
 
 
static string Tr (string s, string c, int n)
 
 
static string TrUtf8 (string s, string c=null)
 
 
static string TrUtf8 (string s, string c, int n)
 
 
- Static Public Member Functions inherited from QtCore.Qt
static QDataStream Write (QDataStream s, object p)
 
static QDataStream Write (QDataStream arg1, QSizeF arg2)
 
static QTextStream Write (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Write (QDataStream arg1, QPoint arg2)
 
static QDataStream Write (QDataStream arg1, QLineF arg2)
 
static QDataStream Write (QDataStream arg1, QPointF arg2)
 
static QDataStream Write (QDataStream arg1, QChar arg2)
 
static QDataStream Write (QDataStream arg1, QByteArray arg2)
 
static QDataStream Write (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Write (QDataStream arg1, QRectF arg2)
 
static QDataStream Write (QDataStream arg1, QDateTime arg2)
 
static QDataStream Write (QDataStream arg1, QUrl arg2)
 
static QDataStream Write (QDataStream arg1, QTime arg2)
 
static QDataStream Write (QDataStream arg1, QLocale arg2)
 
static QDataStream Write (QDataStream arg1, QBitArray arg2)
 
static QDataStream Write (QDataStream arg1, QUuid arg2)
 
static QDataStream Write (QDataStream arg1, QLine arg2)
 
static QDataStream Write (QDataStream arg1, QDate arg2)
 
static QDataStream Write (QDataStream @out, QRegExp regExp)
 
static QDataStream Write (QDataStream arg1, QRect arg2)
 
static QDataStream Write (QDataStream arg1, QSize arg2)
 
static QDataStream Write (QDataStream s, QVariant.Type p)
 
static QDataStream Write (QDataStream arg1, string arg2)
 
static QDataStream Write (QDataStream @out, System.Collections.Generic.List< string > list)
 
static QDataStream Read (QDataStream arg1, QChar arg2)
 
static QDataStream Read (QDataStream arg1, QLocale arg2)
 
static QDataStream Read (QDataStream arg1, QRect arg2)
 
static QDataStream Read (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Read (QDataStream arg1, QDate arg2)
 
static QDataStream Read (QDataStream arg1, QUrl arg2)
 
static QDataStream Read (QDataStream arg1, QUuid arg2)
 
static QTextStream Read (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Read (QDataStream arg1, QLineF arg2)
 
static QDataStream Read (QDataStream arg1, QRectF arg2)
 
static QDataStream Read (QDataStream arg1, QPointF arg2)
 
static QDataStream Read (QDataStream arg1, QLine arg2)
 
static QDataStream Read (QDataStream arg1, QBitArray arg2)
 
static QDataStream Read (QDataStream arg1, QSize arg2)
 
static QDataStream Read (QDataStream arg1, QDateTime arg2)
 
static QDataStream Read (QDataStream arg1, QTime arg2)
 
static QDataStream Read (QDataStream arg1, QPoint arg2)
 
static QDataStream Read (QDataStream @in, QRegExp regExp)
 
static QDataStream Read (QDataStream s, object p)
 
static QDataStream Read (QDataStream arg1, QByteArray arg2)
 
static QDataStream Read (QDataStream arg1, QSizeF arg2)
 
static QDataStream Read (QDataStream arg1, string arg2)
 
static QDataStream Read (QDataStream s, QVariant.Type p)
 
static QDataStream Read (QDataStream @in, System.Collections.Generic.List< string > list)
 
static double qAcos (double v)
 
static void qAddPostRoutine (System.Action arg1)
 
static string qAppName ()
 
static double qAsin (double v)
 
static double qAtan (double v)
 
static double qAtan2 (double x, double y)
 
static void qBadAlloc ()
 
static int qCeil (double v)
 
static ushort qChecksum (string s, uint len)
 
static QByteArray qCompress (QByteArray data)
 
static QByteArray qCompress (QByteArray data, int compressionLevel=-1)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1)
 
static double qCos (double v)
 
static double qExp (double v)
 
static double qFabs (double v)
 
static double qFastCos (double x)
 
static double qFastSin (double x)
 
static string qFlagLocation (string method)
 
static int qFloor (double v)
 
static bool qFuzzyCompare (double p1, double p2)
 
static bool qFuzzyCompare (float p1, float p2)
 
static bool qFuzzyIsNull (double d)
 
static bool qFuzzyIsNull (float f)
 
static uint qHash (QBitArray key)
 
static uint qHash (QChar key)
 
static uint qHash (QStringRef key)
 
static uint qHash (QUrl url)
 
static uint qHash (QPersistentModelIndex index)
 
static uint qHash (QByteArray key)
 
static uint qHash (QModelIndex index)
 
static uint qHash (uint key)
 
static uint qHash (sbyte key)
 
static uint qHash (byte key)
 
static uint qHash (short key)
 
static uint qHash (NativeLong key)
 
static uint qHash (ushort key)
 
static uint qHash (long key)
 
static uint qHash (ulong key)
 
static uint qHash (int key)
 
static uint qHash (string key)
 
static uint qHash (NativeULong key)
 
static double qInf ()
 
static Qt.ActionQtMsgTypeString qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1)
 
static int qIntCast (float f)
 
static int qIntCast (double f)
 
static bool qIsFinite (double d)
 
static bool qIsFinite (float f)
 
static bool qIsInf (float f)
 
static bool qIsInf (double d)
 
static bool qIsNaN (float f)
 
static bool qIsNaN (double d)
 
static bool qIsNull (float f)
 
static bool qIsNull (double d)
 
static double qLn (double v)
 
static double qPow (double x, double y)
 
static double qQNaN ()
 
static void qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function)
 
static void qRemovePostRoutine (System.Action arg1)
 
static int qRound (double d)
 
static long qRound64 (double d)
 
static double qSNaN ()
 
static bool qSharedBuild ()
 
static double qSin (double v)
 
static double qSqrt (double v)
 
static bool qStringComparisonHelper (QStringRef s1, string s2)
 
static double qTan (double v)
 
static QByteArray qUncompress (QByteArray data)
 
static QByteArray qUncompress (Pointer< byte > data, int nbytes)
 
static string qVersion ()
 
static void Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size)
 
static QByteArray Qgetenv (string varName)
 
static bool Qputenv (string varName, QByteArray value)
 
static int Qrand ()
 
static void Qsrand (uint seed)
 
static int Qstrcmp (QByteArray str1, QByteArray str2)
 
static int Qstrcmp (QByteArray str1, string str2)
 
static int Qstrcmp (string str1, QByteArray str2)
 
static int Qstrcmp (string str1, string str2)
 
static Pointer< sbyte > Qstrcpy (Pointer< sbyte > dst, string src)
 
static Pointer< sbyte > Qstrdup (string arg1)
 
static int Qstricmp (string arg1, string arg2)
 
static uint Qstrlen (string str)
 
static int Qstrncmp (string str1, string str2, uint len)
 
static Pointer< sbyte > Qstrncpy (Pointer< sbyte > dst, string src, uint len)
 
static int Qstrnicmp (string arg1, string arg2, uint len)
 
static uint Qstrnlen (string str, uint maxlen)
 
static string QtTrId (string id, int n=-1)
 

Protected Member Functions

 QAbstractItemDelegate (System.Type dummy)
 
new void OnCloseEditor (QWidget editor, QAbstractItemDelegate.EndEditHint hint=QAbstractItemDelegate.EndEditHint.NoHint)
 
 
new void OnCommitData (QWidget editor)
 
 
new void OnSizeHintChanged (QModelIndex arg1)
 
 
- Protected Member Functions inherited from QtCore.QObject
 QObject (System.Type dummy)
 
virtual void OnChildEvent (QChildEvent arg1)
 
 
virtual void ConnectNotify (string signal)
 
 
virtual void OnCustomEvent (QEvent arg1)
 
 
new void OnDestroyed (QObject arg1=null)
 
 
virtual void DisconnectNotify (string signal)
 
 
new int Receivers (string signal)
 
 
new QObject Sender ()
 
 
new int SenderSignalIndex ()
 
 
virtual void OnTimerEvent (QTimerEvent arg1)
 
 

Properties

Slot< QWidgetCommitData
 
 
Slot< QWidget,
QAbstractItemDelegate.EndEditHint
CloseEditor
 
 
Slot< QWidgetCloseEditorEditor
 
Slot< QModelIndexSizeHintChanged
 
 
static new QMetaObject StaticMetaObject [get]
 
new IQAbstractItemDelegateSignals Emit [get]
 
- Properties inherited from QtCore.QObject
virtual EventHandler
< QEventArgs< QChildEvent > > 
ChildEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
CustomEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
Event
 
 
virtual EventHandler
< QEventArgs< QTimerEvent > > 
TimerEvent
 
 
Slot< QObjectDestroyedQObject
 
Slot Destroyed
 
 
new QObject Parent [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 
new string ObjectName [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
 
static new QMetaObject StaticQtMetaObject [get]
 
new IQObjectSignals Emit [get]
 

Additional Inherited Members

- Protected Attributes inherited from QtCore.QObject
object Q_EMIT = null
 
SmokeInvocation interceptor
 
readonly List< QEventHandler > eventFilters = new List<QEventHandler>()
 

Detailed Description

The QAbstractItemDelegate class is used to display and edit data items from a model.

A QAbstractItemDelegate provides the interface and common functionality for delegates in the model/view architecture. Delegates display individual items in views, and handle the editing of model data.

The QAbstractItemDelegate class is one of the Model/View Classes and is part of Qt's model/view framework.

To render an item in a custom way, you must implement paint() and sizeHint(). The QItemDelegate class provides default implementations for these functions; if you do not need custom rendering, subclass that class instead.

We give an example of drawing a progress bar in items; in our case for a package management program.

We create the WidgetDelegate class, which inherits from QStyledItemDelegate. We do the drawing in the paint() function:

void WidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,

const QModelIndex &index) const

{

if (index.column() == 1) {

int progress = index.data().toInt();

QStyleOptionProgressBar progressBarOption;

progressBarOption.rect = option.rect;

progressBarOption.minimum = 0;

progressBarOption.maximum = 100;

progressBarOption.progress = progress;

progressBarOption.text = QString::number(progress) + "%";

progressBarOption.textVisible = true;

QApplication::style()->drawControl(QStyle::CE_ProgressBar,

&progressBarOption, painter);

} else

QStyledItemDelegate::paint(painter, option, index);

Notice that we use a QStyleOptionProgressBar and initialize its members. We can then use the current QStyle to draw it.

To provide custom editing, there are two approaches that can be used. The first approach is to create an editor widget and display it directly on top of the item. To do this you must reimplement createEditor() to provide an editor widget, setEditorData() to populate the editor with the data from the model, and setModelData() so that the delegate can update the model with data from the editor.

The second approach is to handle user events directly by reimplementing editorEvent().

See also Model/View Programming, QItemDelegate, Pixelator Example, QStyledItemDelegate, and QStyle.

Member Enumeration Documentation

This enum describes the different hints that the delegate can give to the model and view components to make editing data in a model a comfortable experience for the user.

These hints let the delegate influence the behavior of the view:

Note that custom views may interpret the concepts of next and previous differently.

The following hints are most useful when models are used that cache data, such as those that manipulate data locally in order to increase performance or conserve network bandwidth.

Although models and views should respond to these hints in appropriate ways, custom components may ignore any or all of them if they are not relevant.

Enumerator:
EditNextItem 

The view should use the delegate to open an editor on the next item in the view.

EditPreviousItem 

The view should use the delegate to open an editor on the previous item in the view.

NoHint 

There is no recommended action to be performed.

RevertModelCache 

If the model caches data, it should discard cached data and replace it with data from the underlying data store.

SubmitModelCache 

If the model caches data, it should write out cached data to the underlying data store.

Constructor & Destructor Documentation

QtGui.QAbstractItemDelegate.QAbstractItemDelegate ( System.Type  dummy)
protected
QtGui.QAbstractItemDelegate.QAbstractItemDelegate ( QObject  parent = null)

Creates a new abstract item delegate with the given parent.

Member Function Documentation

virtual QWidget QtGui.QAbstractItemDelegate.CreateEditor ( QWidget  parent,
QStyleOptionViewItem  option,
QModelIndex  index 
)
virtual

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 setModelData() and setEditorData().

Reimplemented in QtGui.QStyledItemDelegate, QtGui.QItemDelegate, and QtSql.QSqlRelationalDelegate.

override void QtGui.QAbstractItemDelegate.CreateProxy ( )
virtual
new void QtGui.QAbstractItemDelegate.Dispose ( )
static string QtGui.QAbstractItemDelegate.ElidedText ( QFontMetrics  fontMetrics,
int  width,
Qt.TextElideMode  mode,
string  text 
)
static

Use QFontMetrics::elidedText() instead.

For example, if you have code like

QFontMetrics fm = ...

QString str = QAbstractItemDelegate::elidedText(fm, width, mode, text);

you can rewrite it as

QFontMetrics fm = ...

QString str = fm.elidedText(text, mode, width);

new void QtGui.QAbstractItemDelegate.OnCloseEditor ( QWidget  editor,
QAbstractItemDelegate.EndEditHint  hint = QAbstractItemDelegate.EndEditHint.NoHint 
)
protected

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.

new void QtGui.QAbstractItemDelegate.OnCommitData ( QWidget  editor)
protected

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

virtual bool QtGui.QAbstractItemDelegate.OnEditorEvent ( QEvent event,
QAbstractItemModel  model,
QStyleOptionViewItem  option,
QModelIndex  index 
)
virtual

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).

Reimplemented in QtGui.QStyledItemDelegate, and QtGui.QItemDelegate.

new bool QtGui.QAbstractItemDelegate.OnHelpEvent ( QHelpEvent event,
QAbstractItemView  view,
QStyleOptionViewItem  option,
QModelIndex  index 
)

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.

new void QtGui.QAbstractItemDelegate.OnSizeHintChanged ( QModelIndex  arg1)
protected

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.

abstract void QtGui.QAbstractItemDelegate.Paint ( QPainter  painter,
QStyleOptionViewItem  option,
QModelIndex  index 
)
pure virtual

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().

Implemented in QtGui.QStyledItemDelegate, and QtGui.QItemDelegate.

virtual void QtGui.QAbstractItemDelegate.SetEditorData ( QWidget  editor,
QModelIndex  index 
)
virtual

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().

Reimplemented in QtGui.QStyledItemDelegate, QtGui.QItemDelegate, and QtSql.QSqlRelationalDelegate.

virtual void QtGui.QAbstractItemDelegate.SetModelData ( QWidget  editor,
QAbstractItemModel  model,
QModelIndex  index 
)
virtual

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().

Reimplemented in QtGui.QStyledItemDelegate, QtGui.QItemDelegate, and QtSql.QSqlRelationalDelegate.

abstract QSize QtGui.QAbstractItemDelegate.SizeHint ( QStyleOptionViewItem  option,
QModelIndex  index 
)
pure virtual

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().

Implemented in QtGui.QStyledItemDelegate, and QtGui.QItemDelegate.

static string QtGui.QAbstractItemDelegate.Tr ( string  s,
string  c = null 
)
static
static string QtGui.QAbstractItemDelegate.Tr ( string  s,
string  c,
int  n 
)
static
static string QtGui.QAbstractItemDelegate.TrUtf8 ( string  s,
string  c = null 
)
static
static string QtGui.QAbstractItemDelegate.TrUtf8 ( string  s,
string  c,
int  n 
)
static
virtual void QtGui.QAbstractItemDelegate.UpdateEditorGeometry ( QWidget  editor,
QStyleOptionViewItem  option,
QModelIndex  index 
)
virtual

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.

Reimplemented in QtGui.QStyledItemDelegate, and QtGui.QItemDelegate.

Property Documentation

Slot<QWidget,QAbstractItemDelegate.EndEditHint> QtGui.QAbstractItemDelegate.CloseEditor
addremove

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.

Slot<QWidget> QtGui.QAbstractItemDelegate.CloseEditorEditor
addremove
Slot<QWidget> QtGui.QAbstractItemDelegate.CommitData
addremove

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

new IQAbstractItemDelegateSignals QtGui.QAbstractItemDelegate.Emit
getprotected
Slot<QModelIndex> QtGui.QAbstractItemDelegate.SizeHintChanged
addremove

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.

new QMetaObject QtGui.QAbstractItemDelegate.StaticMetaObject
staticget