Qt 4.8
qstyleditemdelegate.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qstyleditemdelegate.h"
43 
44 #ifndef QT_NO_ITEMVIEWS
45 #include <qabstractitemmodel.h>
46 #include <qapplication.h>
47 #include <qbrush.h>
48 #include <qlineedit.h>
49 #include <qtextedit.h>
50 #include <qplaintextedit.h>
51 #include <qpainter.h>
52 #include <qpalette.h>
53 #include <qpoint.h>
54 #include <qrect.h>
55 #include <qsize.h>
56 #include <qstyle.h>
57 #include <qdatetime.h>
58 #include <qstyleoption.h>
59 #include <qevent.h>
60 #include <qpixmap.h>
61 #include <qbitmap.h>
62 #include <qpixmapcache.h>
63 #include <qitemeditorfactory.h>
64 #include <private/qitemeditorfactory_p.h>
65 #include <qmetaobject.h>
66 #include <qtextlayout.h>
67 #include <private/qobject_p.h>
68 #include <private/qdnd_p.h>
69 #include <private/qtextengine_p.h>
70 #include <private/qlayoutengine_p.h>
71 #include <qdebug.h>
72 #include <qlocale.h>
73 #include <qdialog.h>
74 #include <qtableview.h>
75 
76 #include <limits.h>
77 
79 
81 {
83 
84 public:
86 
87  static const QWidget *widget(const QStyleOptionViewItem &option)
88  {
89  if (const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option))
90  return v3->widget;
91  return 0;
92  }
93 
95  {
97  }
98 
100  {
102  emit q->commitData(editor);
103  emit q->closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
104  }
106 };
107 
251 {
252 }
253 
258 {
259 }
260 
274 QString QStyledItemDelegate::displayText(const QVariant &value, const QLocale& locale) const
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 }
312 
323  const QModelIndex &index) const
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 }
396 
422  const QStyleOptionViewItem &option, const QModelIndex &index) const
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 }
433 
445  const QModelIndex &index) const
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 }
457 
466  const QStyleOptionViewItem &,
467  const QModelIndex &index) const
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 }
475 
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 }
517 
528  QAbstractItemModel *model,
529  const QModelIndex &index) const
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 }
547 
553  const QStyleOptionViewItem &option,
554  const QModelIndex &index) const
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 }
585 
593 {
594  Q_D(const QStyledItemDelegate);
595  return d->factory;
596 }
597 
606 {
608  d->factory = factory;
609 }
610 
611 
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 }
708 
713  QAbstractItemModel *model,
714  const QStyleOptionViewItem &option,
715  const QModelIndex &index)
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 }
761 
763 
764 #include "moc_qstyleditemdelegate.cpp"
765 
766 #endif // QT_NO_ITEMVIEWS
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
CheckState
Definition: qnamespace.h:1607
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QAbstractItemDelegate class is used to display and edit data items from a model.
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
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QFont font
the font used for the item
Definition: qstyleoption.h:552
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
The QItemEditorFactory class provides widgets for editing item data in views and delegates.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Q_GUI_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
QPointer< QWidget > widget
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
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...
bool isActiveWindow
whether this widget&#39;s window is the active window
Definition: qwidget.h:186
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
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
~QStyledItemDelegate()
Destroys the item delegate.
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.
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
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
State
This enum describes the state for which a pixmap is intended to be used.
Definition: qicon.h:64
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
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...
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
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
#define Q_D(Class)
Definition: qglobal.h:2482
const QItemEditorFactory * editorFactory() const
The QStyledItemDelegate class provides display and editing facilities for data items from a model...
static const QWidget * widget(const QStyleOptionViewItem &option)
QString toString(qlonglong i) const
Returns a localized string representation of i.
Definition: qlocale.cpp:1295
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
#define Q_Q(Class)
Definition: qglobal.h:2483
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.
int width() const
Returns the width.
Definition: qsize.h:126
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the widget used to edit the item specified by index for editing.
QItemEditorFactory * itemEditorFactory() const
Returns the editor factory used by the item delegate.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
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
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
The QStyleOptionViewItemV3 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:590
QStyledItemDelegate(QObject *parent=0)
Constructs an item delegate with the given parent.
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
#define emit
Definition: qobjectdefs.h:76
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
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
bool showDecorationSelected
whether the decoration should be highlighted on selected items
Definition: qstyleoption.h:553
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
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.
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
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
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.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
int count() const
Definition: qstring.h:103
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
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
The QAbstractItemModel class provides the abstract interface for item model classes.
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
Qt::LayoutDirection layoutDirection
the layout direction for this widget
Definition: qwidget.h:216
static QDragManager * self()
Definition: qdnd.cpp:163
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...
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
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
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
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
Reimplemented Function
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
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.
void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint=NoHint)
This signal is emitted when the user has finished editing an item using the specified editor...
const char * name() const
Returns this property&#39;s name.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void setItemEditorFactory(QItemEditorFactory *factory)
Sets the editor factory to be used by the item delegate to be the factory specified.
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Qt::Alignment displayAlignment
the alignment of the display value for the item
Definition: qstyleoption.h:547
int key
The QModelIndex class is used to locate data in a data model.
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...
QSize decorationSize
the size of the decoration for the item
Definition: qstyleoption.h:551
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
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 mode...
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
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...
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
quint16 index
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QObject * parent
Definition: qobject.h:92
QMetaProperty userProperty() const
Returns the property that has the USER flag set to true.
virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
Initialize option with the values using the index index.
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.
static const QItemEditorFactory * defaultFactory()
Returns the default item editor factory.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
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 QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
void _q_commitDataAndCloseEditor(QWidget *editor)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
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...
#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
bool eventFilter(QObject *object, QEvent *event)
Returns true if the given editor is a valid QWidget and the given event is handled; otherwise returns...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
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 t...
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
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
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60