Qt 4.8
Public Functions | Protected Functions | List of all members
QStyledItemDelegate Class Reference

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

#include <qstyleditemdelegate.h>

Inheritance diagram for QStyledItemDelegate:
QAbstractItemDelegate QObject QPPDOptionsEditor QScriptBreakpointsItemDelegate QScriptDebuggerLocalsItemDelegate QSideBarDelegate

Public Functions

QWidgetcreateEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 Returns the widget used to edit the item specified by index for editing. More...
 
virtual QString displayText (const QVariant &value, const QLocale &locale) const
 This function returns the string that the delegate will use to display the Qt::DisplayRole of the model in locale. More...
 
QItemEditorFactoryitemEditorFactory () const
 Returns the editor factory used by the item delegate. More...
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
 Renders the delegate using the given painter and style option for the item specified by index. More...
 
 QStyledItemDelegate (QObject *parent=0)
 Constructs an item delegate with the given parent. More...
 
void setEditorData (QWidget *editor, const QModelIndex &index) const
 Sets the data to be displayed and edited by the editor from the data model item specified by the model index. More...
 
void setItemEditorFactory (QItemEditorFactory *factory)
 Sets the editor factory to be used by the item delegate to be the factory specified. More...
 
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
 Gets data from the editor widget and stores it in the specified model at the item index. More...
 
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const
 Returns the size needed by the delegate to display the item specified by index, taking into account the style information provided by option. More...
 
void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
 Updates the editor for the item specified by index according to the style option given. More...
 
 ~QStyledItemDelegate ()
 Destroys the item delegate. More...
 
- Public Functions inherited from QAbstractItemDelegate
 QAbstractItemDelegate (QObject *parent=0)
 Creates a new abstract item delegate with the given parent. More...
 
virtual ~QAbstractItemDelegate ()
 Destroys the abstract item delegate. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

bool editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
 Reimplemented Function More...
 
bool eventFilter (QObject *object, QEvent *event)
 Returns true if the given editor is a valid QWidget and the given event is handled; otherwise returns false. More...
 
virtual void initStyleOption (QStyleOptionViewItem *option, const QModelIndex &index) const
 Initialize option with the values using the index index. More...
 
- Protected Functions inherited from QAbstractItemDelegate
 QAbstractItemDelegate (QObjectPrivate &, QObject *parent=0)
 Creates a new abstract item delegate with the given parent. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Additional Inherited Members

- Public Types inherited from QAbstractItemDelegate
enum  EndEditHint {
  NoHint, EditNextItem, EditPreviousItem, SubmitModelCache,
  RevertModelCache
}
 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. More...
 
- Public Slots inherited from QAbstractItemDelegate
bool helpEvent (QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const 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. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractItemDelegate
void closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint=NoHint)
 This signal is emitted when the user has finished editing an item using the specified editor. More...
 
void commitData (QWidget *editor)
 This signal must be emitted when the editor widget has completed editing the data, and wants to write it back into the model. More...
 
void sizeHintChanged (const QModelIndex &)
 This signal must be emitted when the sizeHint() of index changed. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QAbstractItemDelegate
static QString elidedText (const QFontMetrics &fontMetrics, int width, Qt::TextElideMode mode, const QString &text)
 Use QFontMetrics::elidedText() instead. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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

Since
4.4

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 Programming{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 Qt::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.

Role Accepted Types
Warning
This function is not part of the public interface.
Qt::AccessibleDescriptionRole QString
Qt::AccessibleTextRole QString

Qt::BackgroundRole

QBrush

Qt::BackgroundColorRole

QColor (obsolete; use Qt::BackgroundRole instead)

Qt::CheckStateRole

Qt::CheckState

Qt::DecorationRole

QIcon, QPixmap, QImage and QColor

Qt::DisplayRole

QString and types with a string representation

Qt::EditRole

See QItemEditorFactory for details

Qt::FontRole

QFont

Qt::SizeHintRole

QSize

Warning
This function is not part of the public interface.

Qt::StatusTipRole

Qt::TextAlignmentRole

Qt::Alignment

Qt::ForegroundRole

QBrush

Qt::TextColorRole

QColor (obsolete; use Qt::ForegroundRole instead)

Warning
This function is not part of the public interface.

Qt::ToolTipRole

Qt::WhatsThisRole

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 Qt::EditRole that is edited. See the QItemEditorFactory class for a more high-level introduction to item editor factories. The Color Editor Factory Example{Color Editor Factory} example shows how to create custom editors with a factory.

Subclassing QStyledItemDelegate

If the delegate does not support painting of the data types you need or you want to customize the drawing of items, you need to subclass QStyledItemDelegate, and reimplement paint() and possibly sizeHint(). The paint() function is called individually for each item, and with sizeHint(), you can specify the hint for each of them.

When reimplementing paint(), one would typically handle the datatypes one would like to draw and use the superclass implementation for other types.

The painting of check box indicators are performed by the current style. The style also specifies the size and the bounding rectangles in which to draw the data for the different data roles. The bounding rectangle of the item itself is also calculated by the style. When drawing already supported datatypes, it is therefore a good idea to ask the style for these bounding rectangles. The QStyle class description describes this in more detail.

If you wish to change any of the bounding rectangles calculated by the style or the painting of check box indicators, you can subclass QStyle. Note, however, that the size of the items can also be affected by reimplementing sizeHint().

It is possible for a custom delegate to provide editors without the use of an editor item factory. In this case, the following virtual functions must be reimplemented:

The Star Delegate Example{Star Delegate} example creates editors by reimplementing these methods.

.-QItemDelegate

QStyledItemDelegate vs. QItemDelegate

Since Qt 4.4, there are two delegate classes: QItemDelegate and QStyledItemDelegate. However, the default delegate is QStyledItemDelegate. These two classes are independent alternatives to painting and providing editors for items in views. The difference between them is that QStyledItemDelegate uses the current style to paint its items. We therefore recommend using QStyledItemDelegate as the base class when implementing custom delegates or when working with Qt style sheets. The code required for either class should be equal unless the custom delegate needs to use the style for drawing.

If you wish to customize the painting of item views, you should implement a custom style. Please see the QStyle class documentation for details.

See also
{Delegate Classes}, QItemDelegate, QAbstractItemDelegate, QStyle, {Spin Box Delegate Example}, {Star Delegate Example}, {Color Editor Factory Example}

Definition at line 61 of file qstyleditemdelegate.h.

Constructors and Destructors

◆ QStyledItemDelegate()

QStyledItemDelegate::QStyledItemDelegate ( QObject parent = 0)
explicit

Constructs an item delegate with the given parent.

Definition at line 249 of file qstyleditemdelegate.cpp.

251 {
252 }
QAbstractItemDelegate(QObject *parent=0)
Creates a new abstract item delegate with the given parent.

◆ ~QStyledItemDelegate()

QStyledItemDelegate::~QStyledItemDelegate ( )

Destroys the item delegate.

Definition at line 257 of file qstyleditemdelegate.cpp.

258 {
259 }

Functions

◆ createEditor()

QWidget * QStyledItemDelegate::createEditor ( QWidget parent,
const QStyleOptionViewItem option,
const QModelIndex index 
) const
virtual

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

Reimplemented from QAbstractItemDelegate.

Reimplemented in QScriptBreakpointsItemDelegate, and QScriptDebuggerLocalsItemDelegate.

Definition at line 465 of file qstyleditemdelegate.cpp.

Referenced by QScriptDebuggerLocalsItemDelegate::createEditor(), and QScriptBreakpointsItemDelegate::createEditor().

468 {
469  Q_D(const QStyledItemDelegate);
470  if (!index.isValid())
471  return 0;
472  QVariant::Type t = static_cast<QVariant::Type>(index.data(Qt::EditRole).userType());
473  return d->editorFactory()->createEditor(t, parent);
474 }
double d
Definition: qnumeric_p.h:62
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
#define Q_D(Class)
Definition: qglobal.h:2482
The QStyledItemDelegate class provides display and editing facilities for data items from a model...
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913

◆ displayText()

QString QStyledItemDelegate::displayText ( const QVariant value,
const QLocale locale 
) const
virtual

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

Definition at line 274 of file qstyleditemdelegate.cpp.

Referenced by initStyleOption().

275 {
276  QString text;
277  switch (value.userType()) {
278  case QMetaType::Float:
279  case QVariant::Double:
280  text = locale.toString(value.toReal());
281  break;
282  case QVariant::Int:
283  case QVariant::LongLong:
284  text = locale.toString(value.toLongLong());
285  break;
286  case QVariant::UInt:
287  case QVariant::ULongLong:
288  text = locale.toString(value.toULongLong());
289  break;
290  case QVariant::Date:
291  text = locale.toString(value.toDate(), QLocale::ShortFormat);
292  break;
293  case QVariant::Time:
294  text = locale.toString(value.toTime(), QLocale::ShortFormat);
295  break;
296  case QVariant::DateTime:
297  text = locale.toString(value.toDateTime().date(), QLocale::ShortFormat);
298  text += QLatin1Char(' ');
299  text += locale.toString(value.toDateTime().time(), QLocale::ShortFormat);
300  break;
301  default:
302  // convert new lines into line separators
303  text = value.toString();
304  for (int i = 0; i < text.count(); ++i) {
305  if (text.at(i) == QLatin1Char('\n'))
306  text[i] = QChar::LineSeparator;
307  }
308  break;
309  }
310  return text;
311 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString toString(qlonglong i) const
Returns a localized string representation of i.
Definition: qlocale.cpp:1295
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
Definition: qvariant.cpp:2675
int count() const
Definition: qstring.h:103
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
QTime toTime() const
Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2330
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740
#define text
Definition: qobjectdefs.h:80

◆ editorEvent()

bool QStyledItemDelegate::editorEvent ( QEvent event,
QAbstractItemModel model,
const QStyleOptionViewItem option,
const QModelIndex index 
)
protectedvirtual

Reimplemented Function

Reimplemented from QAbstractItemDelegate.

Definition at line 712 of file qstyleditemdelegate.cpp.

716 {
717  Q_ASSERT(event);
718  Q_ASSERT(model);
719 
720  // make sure that the item is checkable
721  Qt::ItemFlags flags = model->flags(index);
722  if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled)
723  || !(flags & Qt::ItemIsEnabled))
724  return false;
725 
726  // make sure that we have a check state
727  QVariant value = index.data(Qt::CheckStateRole);
728  if (!value.isValid())
729  return false;
730 
732  QStyle *style = widget ? widget->style() : QApplication::style();
733 
734  // make sure that we have the right event type
735  if ((event->type() == QEvent::MouseButtonRelease)
736  || (event->type() == QEvent::MouseButtonDblClick)
737  || (event->type() == QEvent::MouseButtonPress)) {
738  QStyleOptionViewItemV4 viewOpt(option);
739  initStyleOption(&viewOpt, index);
740  QRect checkRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, widget);
741  QMouseEvent *me = static_cast<QMouseEvent*>(event);
742  if (me->button() != Qt::LeftButton || !checkRect.contains(me->pos()))
743  return false;
744 
745  if ((event->type() == QEvent::MouseButtonPress)
746  || (event->type() == QEvent::MouseButtonDblClick))
747  return true;
748 
749  } else if (event->type() == QEvent::KeyPress) {
750  if (static_cast<QKeyEvent*>(event)->key() != Qt::Key_Space
751  && static_cast<QKeyEvent*>(event)->key() != Qt::Key_Select)
752  return false;
753  } else {
754  return false;
755  }
756 
757  Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
759  return model->setData(index, state, Qt::CheckStateRole);
760 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
CheckState
Definition: qnamespace.h:1607
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QPointer< QWidget > widget
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
static QStyle * style()
Returns the application&#39;s style object.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
static const QWidget * widget(const QStyleOptionViewItem &option)
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
int key
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
Initialize option with the values using the index index.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
Type type() const
Returns the event type.
Definition: qcoreevent.h:303

◆ eventFilter()

bool QStyledItemDelegate::eventFilter ( QObject editor,
QEvent event 
)
protectedvirtual

Returns true if the given editor is a valid QWidget and the given event is handled; otherwise returns false.

The following key press events are handled by default:

  • Tab
  • Backtab
  • Enter
  • Return
  • Esc

In the case of Tab, Backtab, Enter and Return key press events, the editor's data is comitted to the model and the editor is closed. If the event is a Tab key press the view will open an editor on the next item in the view. Likewise, if the event is a Backtab key press the view will open an editor on the previous item in the view.

If the event is a Esc key press event, the editor is closed without committing its data.

See also
commitData(), closeEditor()

Reimplemented from QObject.

Reimplemented in QScriptBreakpointsItemDelegate, and QScriptDebuggerLocalsItemDelegate.

Definition at line 639 of file qstyleditemdelegate.cpp.

Referenced by QScriptDebuggerLocalsItemDelegate::eventFilter(), and QScriptBreakpointsItemDelegate::eventFilter().

640 {
641  QWidget *editor = qobject_cast<QWidget*>(object);
642  if (!editor)
643  return false;
644  if (event->type() == QEvent::KeyPress) {
645  switch (static_cast<QKeyEvent *>(event)->key()) {
646  case Qt::Key_Tab:
647  emit commitData(editor);
649  return true;
650  case Qt::Key_Backtab:
651  emit commitData(editor);
653  return true;
654  case Qt::Key_Enter:
655  case Qt::Key_Return:
656 #ifndef QT_NO_TEXTEDIT
657  if (qobject_cast<QTextEdit *>(editor) || qobject_cast<QPlainTextEdit *>(editor))
658  return false; // don't filter enter key events for QTextEdit
659  // We want the editor to be able to process the key press
660  // before committing the data (e.g. so it can do
661  // validation/fixup of the input).
662 #endif // QT_NO_TEXTEDIT
663 #ifndef QT_NO_LINEEDIT
664  if (QLineEdit *e = qobject_cast<QLineEdit*>(editor))
665  if (!e->hasAcceptableInput())
666  return false;
667 #endif // QT_NO_LINEEDIT
668  QMetaObject::invokeMethod(this, "_q_commitDataAndCloseEditor",
669  Qt::QueuedConnection, Q_ARG(QWidget*, editor));
670  return false;
671  case Qt::Key_Escape:
672  // don't commit data
674  break;
675  default:
676  return false;
677  }
678  if (editor->parentWidget())
679  editor->parentWidget()->setFocus();
680  return true;
681  } else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) {
682  //the Hide event will take care of he editors that are in fact complete dialogs
683  if (!editor->isActiveWindow() || (QApplication::focusWidget() != editor)) {
685  while (w) { // don't worry about focus changes internally in the editor
686  if (w == editor)
687  return false;
688  w = w->parentWidget();
689  }
690 #ifndef QT_NO_DRAGANDDROP
691  // The window may lose focus during an drag operation.
692  // i.e when dragging involves the taskbar on Windows.
693  if (QDragManager::self() && QDragManager::self()->object != 0)
694  return false;
695 #endif
696 
697  emit commitData(editor);
698  emit closeEditor(editor, NoHint);
699  }
700  } else if (event->type() == QEvent::ShortcutOverride) {
701  if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape) {
702  event->accept();
703  return true;
704  }
705  }
706  return false;
707 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
bool isActiveWindow
whether this widget&#39;s window is the active window
Definition: qwidget.h:186
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define emit
Definition: qobjectdefs.h:76
void commitData(QWidget *editor)
This signal must be emitted when the editor widget has completed editing the data, and wants to write it back into the model.
static QDragManager * self()
Definition: qdnd.cpp:163
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint=NoHint)
This signal is emitted when the user has finished editing an item using the specified editor...
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...

◆ initStyleOption()

void QStyledItemDelegate::initStyleOption ( QStyleOptionViewItem option,
const QModelIndex index 
) const
protectedvirtual

Initialize option with the values using the index index.

This method is useful for subclasses when they need a QStyleOptionViewItem, but don't want to fill in all the information themselves. This function will check the version of the QStyleOptionViewItem and fill in the additional values for a QStyleOptionViewItemV2, QStyleOptionViewItemV3 and QStyleOptionViewItemV4.

See also
QStyleOption::initFrom()

Reimplemented in QSideBarDelegate.

Definition at line 322 of file qstyleditemdelegate.cpp.

Referenced by editorEvent(), QSideBarDelegate::initStyleOption(), paint(), sizeHint(), and updateEditorGeometry().

324 {
325  QVariant value = index.data(Qt::FontRole);
326  if (value.isValid() && !value.isNull()) {
327  option->font = qvariant_cast<QFont>(value).resolve(option->font);
328  option->fontMetrics = QFontMetrics(option->font);
329  }
330 
331  value = index.data(Qt::TextAlignmentRole);
332  if (value.isValid() && !value.isNull())
333  option->displayAlignment = Qt::Alignment(value.toInt());
334 
335  value = index.data(Qt::ForegroundRole);
336  if (value.canConvert<QBrush>())
337  option->palette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value));
338 
339  if (QStyleOptionViewItemV4 *v4 = qstyleoption_cast<QStyleOptionViewItemV4 *>(option)) {
340  v4->index = index;
341  QVariant value = index.data(Qt::CheckStateRole);
342  if (value.isValid() && !value.isNull()) {
344  v4->checkState = static_cast<Qt::CheckState>(value.toInt());
345  }
346 
347  value = index.data(Qt::DecorationRole);
348  if (value.isValid() && !value.isNull()) {
350  switch (value.type()) {
351  case QVariant::Icon: {
352  v4->icon = qvariant_cast<QIcon>(value);
353  QIcon::Mode mode;
354  if (!(option->state & QStyle::State_Enabled))
355  mode = QIcon::Disabled;
356  else if (option->state & QStyle::State_Selected)
357  mode = QIcon::Selected;
358  else
359  mode = QIcon::Normal;
361  v4->decorationSize = v4->icon.actualSize(option->decorationSize, mode, state);
362  break;
363  }
364  case QVariant::Color: {
365  QPixmap pixmap(option->decorationSize);
366  pixmap.fill(qvariant_cast<QColor>(value));
367  v4->icon = QIcon(pixmap);
368  break;
369  }
370  case QVariant::Image: {
371  QImage image = qvariant_cast<QImage>(value);
372  v4->icon = QIcon(QPixmap::fromImage(image));
373  v4->decorationSize = image.size();
374  break;
375  }
376  case QVariant::Pixmap: {
377  QPixmap pixmap = qvariant_cast<QPixmap>(value);
378  v4->icon = QIcon(pixmap);
379  v4->decorationSize = pixmap.size();
380  break;
381  }
382  default:
383  break;
384  }
385  }
386 
387  value = index.data(Qt::DisplayRole);
388  if (value.isValid() && !value.isNull()) {
389  v4->features |= QStyleOptionViewItemV2::HasDisplay;
390  v4->text = displayText(value, v4->locale);
391  }
392 
393  v4->backgroundBrush = qvariant_cast<QBrush>(index.data(Qt::BackgroundRole));
394  }
395 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
CheckState
Definition: qnamespace.h:1607
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
QFont font
the font used for the item
Definition: qstyleoption.h:552
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
State
This enum describes the state for which a pixmap is intended to be used.
Definition: qicon.h:64
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
virtual QString displayText(const QVariant &value, const QLocale &locale) const
This function returns the string that the delegate will use to display the Qt::DisplayRole of the mod...
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition: qicon.h:63
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
Qt::Alignment displayAlignment
the alignment of the display value for the item
Definition: qstyleoption.h:547
QSize decorationSize
the size of the decoration for the item
Definition: qstyleoption.h:551
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
quint16 index
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ itemEditorFactory()

QItemEditorFactory * QStyledItemDelegate::itemEditorFactory ( ) const

Returns the editor factory used by the item delegate.

If no editor factory is set, the function will return null.

See also
setItemEditorFactory()

Definition at line 592 of file qstyleditemdelegate.cpp.

593 {
594  Q_D(const QStyledItemDelegate);
595  return d->factory;
596 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QStyledItemDelegate class provides display and editing facilities for data items from a model...

◆ paint()

void QStyledItemDelegate::paint ( QPainter painter,
const QStyleOptionViewItem option,
const QModelIndex index 
) const
virtual

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; the option will always be an instance of QStyleOptionViewItemV4. Please see its class description for information on its contents.

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

After painting, you should ensure that the painter is returned to its 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(), QStyle::CE_ItemViewItem

Implements QAbstractItemDelegate.

Reimplemented in QScriptDebuggerLocalsItemDelegate.

Definition at line 421 of file qstyleditemdelegate.cpp.

Referenced by QScriptDebuggerLocalsItemDelegate::paint().

423 {
424  Q_ASSERT(index.isValid());
425 
426  QStyleOptionViewItemV4 opt = option;
427  initStyleOption(&opt, index);
428 
430  QStyle *style = widget ? widget->style() : QApplication::style();
431  style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
432 }
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
static QStyle * style()
Returns the application&#39;s style object.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const QWidget * widget(const QStyleOptionViewItem &option)
QStyle * style() const
Definition: qwidget.cpp:2742
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
Initialize option with the values using the index index.

◆ setEditorData()

void QStyledItemDelegate::setEditorData ( QWidget editor,
const QModelIndex index 
) const
virtual

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 Qt's Property System.

See also
QMetaProperty::isUser()

Reimplemented from QAbstractItemDelegate.

Definition at line 485 of file qstyleditemdelegate.cpp.

486 {
487 #ifdef QT_NO_PROPERTIES
488  Q_UNUSED(editor);
489  Q_UNUSED(index);
490 #else
491  Q_D(const QStyledItemDelegate);
492  QVariant v = index.data(Qt::EditRole);
493  QByteArray n = editor->metaObject()->userProperty().name();
494 
495  // ### Qt 5: remove
496  // A work-around for missing "USER true" in qdatetimeedit.h for
497  // QTimeEdit's time property and QDateEdit's date property.
498  // It only triggers if the default user property "dateTime" is
499  // reported for QTimeEdit and QDateEdit.
500  if (n == "dateTime") {
501  if (editor->inherits("QTimeEdit"))
502  n = "time";
503  else if (editor->inherits("QDateEdit"))
504  n = "date";
505  }
506 
507  // ### Qt 5: give QComboBox a USER property
508  if (n.isEmpty() && editor->inherits("QComboBox"))
509  n = d->editorFactory()->valuePropertyName(static_cast<QVariant::Type>(v.userType()));
510  if (!n.isEmpty()) {
511  if (!v.isValid())
512  v = QVariant(editor->property(n).userType(), (const void *)0);
513  editor->setProperty(n, v);
514  }
515 #endif
516 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
#define Q_D(Class)
Definition: qglobal.h:2482
The QStyledItemDelegate class provides display and editing facilities for data items from a model...
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
const char * name() const
Returns this property&#39;s name.
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QMetaProperty userProperty() const
Returns the property that has the USER flag set to true.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ setItemEditorFactory()

void QStyledItemDelegate::setItemEditorFactory ( QItemEditorFactory factory)

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

Definition at line 605 of file qstyleditemdelegate.cpp.

606 {
608  d->factory = factory;
609 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QStyledItemDelegate class provides display and editing facilities for data items from a model...

◆ setModelData()

void QStyledItemDelegate::setModelData ( QWidget editor,
QAbstractItemModel model,
const QModelIndex index 
) const
virtual

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 Qt's Property System.

See also
QMetaProperty::isUser()

Reimplemented from QAbstractItemDelegate.

Reimplemented in QScriptBreakpointsItemDelegate, and QScriptDebuggerLocalsItemDelegate.

Definition at line 527 of file qstyleditemdelegate.cpp.

Referenced by QScriptDebuggerLocalsItemDelegate::setModelData(), and QScriptBreakpointsItemDelegate::setModelData().

530 {
531 #ifdef QT_NO_PROPERTIES
532  Q_UNUSED(model);
533  Q_UNUSED(editor);
534  Q_UNUSED(index);
535 #else
536  Q_D(const QStyledItemDelegate);
537  Q_ASSERT(model);
538  Q_ASSERT(editor);
539  QByteArray n = editor->metaObject()->userProperty().name();
540  if (n.isEmpty())
541  n = d->editorFactory()->valuePropertyName(
542  static_cast<QVariant::Type>(model->data(index, Qt::EditRole).userType()));
543  if (!n.isEmpty())
544  model->setData(index, editor->property(n), Qt::EditRole);
545 #endif
546 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QStyledItemDelegate class provides display and editing facilities for data items from a model...
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
const char * name() const
Returns this property&#39;s name.
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QMetaProperty userProperty() const
Returns the property that has the USER flag set to true.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ sizeHint()

QSize QStyledItemDelegate::sizeHint ( const QStyleOptionViewItem option,
const QModelIndex index 
) const
virtual

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(), QStyle::CT_ItemViewItem

Implements QAbstractItemDelegate.

Definition at line 444 of file qstyleditemdelegate.cpp.

446 {
447  QVariant value = index.data(Qt::SizeHintRole);
448  if (value.isValid())
449  return qvariant_cast<QSize>(value);
450 
451  QStyleOptionViewItemV4 opt = option;
452  initStyleOption(&opt, index);
454  QStyle *style = widget ? widget->style() : QApplication::style();
455  return style->sizeFromContents(QStyle::CT_ItemViewItem, &opt, QSize(), widget);
456 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QPointer< QWidget > widget
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
static QStyle * style()
Returns the application&#39;s style object.
static const QWidget * widget(const QStyleOptionViewItem &option)
QStyle * style() const
Definition: qwidget.cpp:2742
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
Initialize option with the values using the index index.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ updateEditorGeometry()

void QStyledItemDelegate::updateEditorGeometry ( QWidget editor,
const QStyleOptionViewItem option,
const QModelIndex index 
) const
virtual

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

Reimplemented from QAbstractItemDelegate.

Definition at line 552 of file qstyleditemdelegate.cpp.

555 {
556  if (!editor)
557  return;
558  Q_ASSERT(index.isValid());
560 
561  QStyleOptionViewItemV4 opt = option;
562  initStyleOption(&opt, index);
563  // let the editor take up all available space
564  //if the editor is not a QLineEdit
565  //or it is in a QTableView
566 #if !defined(QT_NO_TABLEVIEW) && !defined(QT_NO_LINEEDIT)
567  if (qobject_cast<QExpandingLineEdit*>(editor) && !qobject_cast<const QTableView*>(widget))
569  else
570 #endif
571  opt.showDecorationSelected = true;
572 
573  QStyle *style = widget ? widget->style() : QApplication::style();
574  QRect geom = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, widget);
575  if ( editor->layoutDirection() == Qt::RightToLeft) {
576  const int delta = qSmartMinSize(editor).width() - geom.width();
577  if (delta > 0) {
578  //we need to widen the geometry
579  geom.adjust(-delta, 0, 0, 0);
580  }
581  }
582 
583  editor->setGeometry(geom);
584 }
Q_GUI_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
QPointer< QWidget > widget
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
static QStyle * style()
Returns the application&#39;s style object.
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const QWidget * widget(const QStyleOptionViewItem &option)
QStyle * style() const
Definition: qwidget.cpp:2742
int width() const
Returns the width.
Definition: qsize.h:126
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
bool showDecorationSelected
whether the decoration should be highlighted on selected items
Definition: qstyleoption.h:553
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
Qt::LayoutDirection layoutDirection
the layout direction for this widget
Definition: qwidget.h:216
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
Initialize option with the values using the index index.

The documentation for this class was generated from the following files: