#include <qitemdelegate.h>
Inheritance diagram for QItemDelegate:


QItemDelegate can be used to provide custom display features and editor widgets for item views based on QAbstractItemView subclasses. Using a delegate for this purpose allows the display and editing mechanisms to be customized and developed independently from the model and view.
The QItemDelegate class is one of the {Model/View Classes} and is part of Qt's {Model/View Programming}{model/view framework}.
When displaying items from a custom model in a standard view, it is often sufficient to simply ensure that the model returns appropriate data for each of the {Qt::ItemDataRole}{roles} that determine the appearance of items in views. The default delegate used by Qt's standard views uses this role information to display items in most of the common forms expected by users. However, it is sometimes necessary to have even more control over the appearance of items than the default delegate can provide.
This class provides default implementations of the functions for painting item data in a view, and editing data obtained from a model. Default implementations of the paint() and sizeHint() virtual functions, defined in QAbstractItemDelegate, are provided to ensure that the delegate implements the correct basic behavior expected by views. You can reimplement these functions in subclasses to customize the appearance of items.
Delegates can be used to manipulate item data in two complementary ways: by processing events in the normal manner, or by implementing a custom editor widget. The item delegate takes the approach of providing a widget for editing purposes that can be supplied to QAbstractItemView::setDelegate() or the equivalent function in subclasses of QAbstractItemView.
Only the standard editing functions for widget-based delegates are reimplemented here: editor() returns the widget used to change data from the model; setEditorData() provides the widget with data to manipulate; updateEditorGeometry() ensures that the editor is displayed correctly with respect to the item view; setModelData() returns the updated data to the model; releaseEditor() indicates that the user has completed editing the data, and that the editor widget can be destroyed.
The default delegate used by the standard views supplied with Qt associates each standard role (defined by Qt::ItemDataRole) with certain data types. Models that return data in these types can influence the appearance of the delegate as described in the following table. \table \header \o Role \o Accepted Types \omit \row \o \l Qt::AccessibleDescriptionRole \o QString \row \o \l Qt::AccessibleTextRole \o QString \endomit \row \o \l Qt::BackgroundRole \o QBrush \row \o \l Qt::BackgroundColorRole \o QColor (obsolete; use Qt::BackgroundRole instead) \row \o \l Qt::CheckStateRole \o Qt::CheckState \row \o \l Qt::DecorationRole \o QIcon and QColor \row \o \l Qt::DisplayRole \o QString and types with a string representation \row \o \l Qt::EditRole \o See QItemEditorFactory for details \row \o \l Qt::FontRole \o QFont \row \o \l Qt::SizeHintRole \o QSize \omit \row \o \l Qt::StatusTipRole \o \endomit \row \o \l Qt::TextAlignmentRole \o Qt::Alignment \row \o \l Qt::ForegroundRole \o QBrush \row \o \l Qt::TextColorRole \o QColor (obsolete; use Qt::ForegroundRole instead) \omit \row \o \l Qt::ToolTipRole \row \o \l Qt::WhatsThisRole \endomit \endtable If the default delegate does not allow the level of customization that you need, either for display purposes or for editing data, it is possible to subclass QItemDelegate to implement the desired behavior. @section Subclassing When subclassing QItemDelegate to create a delegate that displays items using a custom renderer, it is important to ensure that the delegate can render items suitably for all the required states; e.g. selected, disabled, checked. The documentation for the paint() function contains some hints to show how this can be achieved. Custom editing features for can be added by subclassing QItemDelegate and reimplementing createEditor(), setEditorData(), setModelData(), and updateEditorGeometry(). This process is described in the \l{Spin Box Delegate example}. \sa {Delegate Classes}, QAbstractItemDelegate, {Spin Box Delegate Example}, {Settings Editor Example}, {Icons Example} Definition at line 40 of file qitemdelegate.h.
Public Member Functions | |
| QItemDelegate (QObject *parent=0) | |
| ~QItemDelegate () | |
| bool | hasClipping () const |
| void | setClipping (bool clip) |
| void | paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| QSize | sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const |
| QWidget * | createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| void | setEditorData (QWidget *editor, const QModelIndex &index) const |
| void | setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const |
| void | updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| QItemEditorFactory * | itemEditorFactory () const |
| void | setItemEditorFactory (QItemEditorFactory *factory) |
Protected Member Functions | |
| virtual void | drawDisplay (QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const |
| virtual void | drawDecoration (QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QPixmap &pixmap) const |
| virtual void | drawFocus (QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const |
| virtual void | drawCheck (QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, Qt::CheckState state) const |
| void | drawBackground (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| void | doLayout (const QStyleOptionViewItem &option, QRect *checkRect, QRect *iconRect, QRect *textRect, bool hint) const |
| QRect | rect (const QStyleOptionViewItem &option, const QModelIndex &index, int role) const |
| bool | eventFilter (QObject *object, QEvent *event) |
| bool | editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) |
| QStyleOptionViewItem | setOptions (const QModelIndex &index, const QStyleOptionViewItem &option) const |
| QPixmap | decoration (const QStyleOptionViewItem &option, const QVariant &variant) const |
| QPixmap * | selected (const QPixmap &pixmap, const QPalette &palette, bool enabled) const |
| QRect | check (const QStyleOptionViewItem &option, const QRect &bounding, const QVariant &variant) const |
| QRect | textRectangle (QPainter *painter, const QRect &rect, const QFont &font, const QString &text) const |
| QItemDelegate::QItemDelegate | ( | QObject * | parent = 0 |
) | [explicit] |
Constructs an item delegate with the given parent.
Definition at line 245 of file qitemdelegate.cpp.
00246 : QAbstractItemDelegate(*new QItemDelegatePrivate(), parent) 00247 { 00248 00249 }
| QItemDelegate::~QItemDelegate | ( | ) |
| bool QItemDelegate::hasClipping | ( | ) | const |
Definition at line 269 of file qitemdelegate.cpp.
References d.
00270 { 00271 Q_D(const QItemDelegate); 00272 return d->clipPainting; 00273 }
| void QItemDelegate::setClipping | ( | bool | clip | ) |
Definition at line 275 of file qitemdelegate.cpp.
References d.
00276 { 00277 Q_D(QItemDelegate); 00278 d->clipPainting = clip; 00279 }
| void QItemDelegate::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.
When reimplementing this function in a subclass, you should update the area held by the option's {QStyleOption::rect}{rect} variable, using the option's {QStyleOption::state}{state} variable to determine the state of the item to be displayed, and adjust the way it is painted accordingly.
For example, a selected item may need to be displayed differently to unselected items, as shown in the following code:
itemviews/pixelator/pixeldelegate.cpp QStyle::State_Selected else
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.
Implements QAbstractItemDelegate.
Definition at line 306 of file qitemdelegate.cpp.
References QIcon::actualSize(), check(), Qt::CheckStateRole, d, decoration(), QStyleOptionViewItem::decorationAlignment, Qt::DecorationRole, QStyleOptionViewItem::decorationSize, Qt::DisplayRole, doLayout(), QVariant::Double, drawBackground(), drawCheck(), drawDecoration(), drawDisplay(), drawFocus(), QStyleOptionViewItemV2::features, QVariant::Icon, index, QIcon::isNull(), QStyleOptionViewItemV2::None, QIcon::paint(), QItemDelegatePrivate::replaceNewLine(), QPainter::restore(), QPainter::save(), QPainter::setClipRect(), setOptions(), QPixmap::size(), QStyleOption::state, textRectangle(), Qt::Unchecked, and value.
Referenced by qdesigner_internal::SheetDelegate::paint(), qdesigner_internal::TreeWidgetDelegate::paint(), QCalendarDelegate::paint(), TorrentViewDelegate::paint(), MessagesItemDelegate::paint(), qdesigner_internal::ActionGroupDelegate::paint(), qdesigner_internal::ColorDelegate::paint(), qdesigner_internal::QPropertyEditorDelegate::paint(), VariantDelegate::paint(), QCompleterItemDelegate::paint(), and QCalendarDelegate::paintCell().
00309 { 00310 Q_D(const QItemDelegate); 00311 Q_ASSERT(index.isValid()); 00312 QStyleOptionViewItemV2 opt = setOptions(index, option); 00313 const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option); 00314 opt.features = v2 ? v2->features : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None); 00315 00316 // prepare 00317 painter->save(); 00318 if (d->clipPainting) 00319 painter->setClipRect(opt.rect); 00320 00321 // get the data and the rectangles 00322 00323 QVariant value; 00324 00325 QIcon icon; 00326 QIcon::Mode iconMode = d->iconMode(option.state); 00327 QIcon::State iconState = d->iconState(option.state); 00328 00329 QPixmap pixmap; 00330 QRect decorationRect; 00331 value = index.data(Qt::DecorationRole); 00332 if (value.isValid()) { 00333 if (value.type() == QVariant::Icon) { 00334 icon = qvariant_cast<QIcon>(value); 00335 decorationRect = QRect(QPoint(0, 0), 00336 icon.actualSize(option.decorationSize, iconMode, iconState)); 00337 } else { 00338 pixmap = decoration(opt, value); 00339 decorationRect = QRect(QPoint(0, 0), pixmap.size()); 00340 } 00341 } 00342 00343 QString text; 00344 QRect displayRect; 00345 value = index.data(Qt::DisplayRole); 00346 if (value.isValid()) { 00347 if (value.type() == QVariant::Double) 00348 text = QLocale().toString(value.toDouble()); 00349 else 00350 text = QItemDelegatePrivate::replaceNewLine(value.toString()); 00351 00352 displayRect = textRectangle(painter, d->textLayoutBounds(opt), opt.font, text); 00353 } 00354 00355 QRect checkRect; 00356 Qt::CheckState checkState = Qt::Unchecked; 00357 value = index.data(Qt::CheckStateRole); 00358 if (value.isValid()) { 00359 checkState = static_cast<Qt::CheckState>(value.toInt()); 00360 checkRect = check(opt, opt.rect, value); 00361 } 00362 00363 // do the layout 00364 00365 doLayout(opt, &checkRect, &decorationRect, &displayRect, false); 00366 00367 // draw the item 00368 00369 drawBackground(painter, opt, index); 00370 drawCheck(painter, opt, checkRect, checkState); 00371 if (!icon.isNull()) 00372 icon.paint(painter, decorationRect, option.decorationAlignment, iconMode, iconState); 00373 else 00374 drawDecoration(painter, opt, decorationRect, pixmap); 00375 drawDisplay(painter, opt, displayRect, text); 00376 drawFocus(painter, opt, text.isEmpty() ? QRect() : displayRect); 00377 00378 // done 00379 painter->restore(); 00380 }
Here is the call graph for this function:

| QSize QItemDelegate::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.
When reimplementing this function, note that in case of text items, QItemDelegate adds a margin (i.e. 2 * QStyle::PM_FocusFrameHMargin) to the length of the text.
Implements QAbstractItemDelegate.
Definition at line 392 of file qitemdelegate.cpp.
References Qt::CheckStateRole, Qt::DecorationRole, Qt::DisplayRole, doLayout(), index, rect(), Qt::SizeHintRole, and value.
Referenced by qdesigner_internal::TreeWidgetDelegate::sizeHint(), qdesigner_internal::ColorDelegate::sizeHint(), qdesigner_internal::SheetDelegate::sizeHint(), and qdesigner_internal::QPropertyEditorDelegate::sizeHint().
00394 { 00395 QVariant value = index.data(Qt::SizeHintRole); 00396 if (value.isValid()) 00397 return qvariant_cast<QSize>(value); 00398 QRect decorationRect = rect(option, index, Qt::DecorationRole); 00399 QRect displayRect = rect(option, index, Qt::DisplayRole); 00400 QRect checkRect = rect(option, index, Qt::CheckStateRole); 00401 00402 doLayout(option, &checkRect, &decorationRect, &displayRect, true); 00403 00404 return (decorationRect|displayRect|checkRect).size(); 00405 }
Here is the call graph for this function:

| QWidget * QItemDelegate::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.
Reimplemented from QAbstractItemDelegate.
Definition at line 415 of file qitemdelegate.cpp.
References d, QItemEditorFactory::defaultFactory(), Qt::EditRole, index, QObject::parent(), and t.
Referenced by qdesigner_internal::ConnectionDelegate::createEditor(), and qdesigner_internal::WidgetBoxItemDelegate::createEditor().
00418 { 00419 Q_D(const QItemDelegate); 00420 if (!index.isValid()) 00421 return 0; 00422 QVariant::Type t = static_cast<QVariant::Type>(index.data(Qt::EditRole).userType()); 00423 const QItemEditorFactory *factory = d->f; 00424 if (factory == 0) 00425 factory = QItemEditorFactory::defaultFactory(); 00426 return factory->createEditor(t, parent); 00427 }
Here is the call graph for this function:

| void QItemDelegate::setEditorData | ( | QWidget * | editor, | |
| const QModelIndex & | index | |||
| ) | const [virtual] |
Sets the data to be displayed and edited by the editor for the item specified by index.
The default implementation uses the editor's user property to set values.
Reimplemented from QAbstractItemDelegate.
Definition at line 438 of file qitemdelegate.cpp.
References d, Qt::EditRole, index, QObject::inherits(), n, QObject::setProperty(), and QVariant::userType().
00439 { 00440 #ifdef QT_NO_PROPERTIES 00441 Q_UNUSED(editor); 00442 Q_UNUSED(index); 00443 #else 00444 Q_D(const QItemDelegate); 00445 QVariant v = index.data(Qt::EditRole); 00446 QByteArray n = editor->metaObject()->userProperty().name(); 00447 00448 // ### Remove in Qt 5: A work-around for missing "USER true" in 00449 // qdatetimeedit.h for QTimeEdit's time property and QDateEdit's date 00450 // property. It only triggers if the default user property "dateTime" is 00451 // reported for QTimeEdit and QDateEdit. 00452 if (n == "dateTime") { 00453 if (editor->inherits("QTimeEdit")) 00454 n = "time"; 00455 else if (editor->inherits("QDateEdit")) 00456 n = "date"; 00457 } 00458 00459 if (n.isEmpty()) 00460 n = d->editorFactory()->valuePropertyName(static_cast<QVariant::Type>(v.userType())); 00461 if (!n.isEmpty()) 00462 editor->setProperty(n, v); 00463 #endif 00464 }
Here is the call graph for this function:

| void QItemDelegate::setModelData | ( | QWidget * | editor, | |
| QAbstractItemModel * | model, | |||
| const QModelIndex & | index | |||
| ) | const [virtual] |
Sets the data for the specified model and item index from that supplied by the editor.
The default implementation uses the editor's user property to get values.
Reimplemented from QAbstractItemDelegate.
Definition at line 475 of file qitemdelegate.cpp.
References d, QAbstractItemModel::data(), Qt::EditRole, index, n, QObject::property(), QAbstractItemModel::setData(), and QVariant::userType().
00478 { 00479 #ifdef QT_NO_PROPERTIES 00480 Q_UNUSED(model); 00481 Q_UNUSED(editor); 00482 Q_UNUSED(index); 00483 #else 00484 Q_D(const QItemDelegate); 00485 Q_ASSERT(model); 00486 Q_ASSERT(editor); 00487 QByteArray n = editor->metaObject()->userProperty().name(); 00488 if (n.isEmpty()) 00489 n = d->editorFactory()->valuePropertyName( 00490 static_cast<QVariant::Type>(model->data(index, Qt::EditRole).userType())); 00491 if (!n.isEmpty()) 00492 model->setData(index, editor->property(n), Qt::EditRole); 00493 #endif 00494 }
Here is the call graph for this function:

| void QItemDelegate::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 501 of file qitemdelegate.cpp.
References check(), Qt::CheckStateRole, decoration(), Qt::DecorationRole, QStyleOptionViewItem::decorationSize, Qt::DisplayRole, doLayout(), QStyleOptionViewItem::font, index, QStyleOption::rect, QItemDelegatePrivate::replaceNewLine(), QWidget::setGeometry(), QStyleOptionViewItem::showDecorationSelected, and textRectangle().
Referenced by qdesigner_internal::ColorDelegate::updateEditorGeometry(), and qdesigner_internal::QPropertyEditorDelegate::updateEditorGeometry().
00504 { 00505 if (!editor) 00506 return; 00507 Q_ASSERT(index.isValid()); 00508 QPixmap pixmap = decoration(option, index.data(Qt::DecorationRole)); 00509 QString text = QItemDelegatePrivate::replaceNewLine(index.data(Qt::DisplayRole).toString()); 00510 QRect pixmapRect = QRect(QPoint(0, 0), option.decorationSize).intersected(pixmap.rect()); 00511 QRect textRect = textRectangle(0, option.rect, option.font, text); 00512 QRect checkRect = check(option, textRect, index.data(Qt::CheckStateRole)); 00513 QStyleOptionViewItem opt = option; 00514 opt.showDecorationSelected = true; // let the editor take up all available space 00515 doLayout(opt, &checkRect, &pixmapRect, &textRect, false); 00516 editor->setGeometry(textRect); 00517 }
Here is the call graph for this function:

| QItemEditorFactory * QItemDelegate::itemEditorFactory | ( | ) | const |
Returns the editor factory used by the item delegate. If no editor factory is set, the function will return null.
Definition at line 525 of file qitemdelegate.cpp.
References d.
00526 { 00527 Q_D(const QItemDelegate); 00528 return d->f; 00529 }
| void QItemDelegate::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.
Definition at line 538 of file qitemdelegate.cpp.
References d.
Referenced by qdesigner_internal::ConnectionDelegate::ConnectionDelegate().
00539 { 00540 Q_D(QItemDelegate); 00541 d->f = factory; 00542 }
| void QItemDelegate::drawDisplay | ( | QPainter * | painter, | |
| const QStyleOptionViewItem & | option, | |||
| const QRect & | rect, | |||
| const QString & | text | |||
| ) | const [protected, virtual] |
Renders the item view text within the rectangle specified by rect using the given painter and style option.
Definition at line 549 of file qitemdelegate.cpp.
References QRect::adjusted(), QStyle::alignedRect(), QPalette::brush(), QPalette::color(), d, QStyleOption::direction, QPalette::Disabled, QStyleOptionViewItem::displayAlignment, QPainter::drawRect(), QFontMetrics::elidedText(), QStyleOptionViewItemV2::features, QPainter::fillRect(), QStyleOptionViewItem::font, QStyleOption::fontMetrics, QRect::height(), QSizeF::height(), QPalette::Highlight, QPalette::HighlightedText, QPalette::Inactive, QString::indexOf(), int, QString::isEmpty(), QChar::LineSeparator, QTextOption::ManualWrap, QPalette::Normal, QStyleOption::palette, QPainter::pen(), QStyle::pixelMetric(), QStyle::PM_FocusFrameHMargin, rect(), QItemDelegatePrivate::replaceNewLine(), QPainter::restore(), QPainter::save(), QPainter::setPen(), start, QStyleOption::state, QStyle::State_Active, QStyle::State_Editing, QStyle::State_Enabled, QStyle::State_Selected, QApplication::style(), QPalette::Text, QStyleOptionViewItem::textElideMode, QRect::topLeft(), QStyle::visualAlignment(), QRect::width(), QSizeF::width(), QTextOption::WordWrap, and QStyleOptionViewItemV2::WrapText.
Referenced by paint().
00551 { 00552 Q_D(const QItemDelegate); 00553 00554 if (text.isEmpty()) 00555 return; 00556 00557 QPen pen = painter->pen(); 00558 QPalette::ColorGroup cg = option.state & QStyle::State_Enabled 00559 ? QPalette::Normal : QPalette::Disabled; 00560 if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) 00561 cg = QPalette::Inactive; 00562 if (option.state & QStyle::State_Selected) { 00563 painter->fillRect(rect, option.palette.brush(cg, QPalette::Highlight)); 00564 painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); 00565 } else { 00566 painter->setPen(option.palette.color(cg, QPalette::Text)); 00567 } 00568 00569 if (option.state & QStyle::State_Editing) { 00570 painter->save(); 00571 painter->setPen(option.palette.color(cg, QPalette::Text)); 00572 painter->drawRect(rect.adjusted(0, 0, -1, -1)); 00573 painter->restore(); 00574 } 00575 00576 const QStyleOptionViewItemV2 opt = option; 00577 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; 00578 QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding 00579 const bool wrapText = opt.features & QStyleOptionViewItemV2::WrapText; 00580 d->textOption.setWrapMode(wrapText ? QTextOption::WordWrap : QTextOption::ManualWrap); 00581 d->textOption.setTextDirection(option.direction); 00582 d->textOption.setAlignment(QStyle::visualAlignment(option.direction, option.displayAlignment)); 00583 d->textLayout.setTextOption(d->textOption); 00584 d->textLayout.setFont(option.font); 00585 d->textLayout.setText(QItemDelegatePrivate::replaceNewLine(text)); 00586 00587 QSizeF textLayoutSize = d->doTextLayout(textRect.width()); 00588 00589 if (textRect.width() < textLayoutSize.width() 00590 || textRect.height() < textLayoutSize.height()) { 00591 QString elided; 00592 int start = 0; 00593 int end = text.indexOf(QChar::LineSeparator, start); 00594 if (end == -1) { 00595 elided += option.fontMetrics.elidedText(text, option.textElideMode, textRect.width()); 00596 } else while (end != -1) { 00597 elided += option.fontMetrics.elidedText(text.mid(start, end - start), 00598 option.textElideMode, textRect.width()); 00599 start = end + 1; 00600 end = text.indexOf(QChar::LineSeparator, start); 00601 } 00602 d->textLayout.setText(elided); 00603 textLayoutSize = d->doTextLayout(textRect.width()); 00604 } 00605 00606 const QSize layoutSize(textRect.width(), int(textLayoutSize.height())); 00607 const QRect layoutRect = QStyle::alignedRect(option.direction, option.displayAlignment, 00608 layoutSize, textRect); 00609 d->textLayout.draw(painter, layoutRect.topLeft(), QVector<QTextLayout::FormatRange>(), layoutRect); 00610 }
Here is the call graph for this function:

| void QItemDelegate::drawDecoration | ( | QPainter * | painter, | |
| const QStyleOptionViewItem & | option, | |||
| const QRect & | rect, | |||
| const QPixmap & | pixmap | |||
| ) | const [protected, virtual] |
Renders the decoration pixmap within the rectangle specified by rect using the given painter and style option.
Definition at line 616 of file qitemdelegate.cpp.
References QStyle::alignedRect(), QStyleOptionViewItem::decorationAlignment, QStyleOption::direction, QPainter::drawPixmap(), QPixmap::isNull(), QRect::isValid(), p, QStyleOption::palette, rect(), selected(), QPixmap::size(), QStyleOption::state, QStyle::State_Enabled, and QStyle::State_Selected.
Referenced by qdesigner_internal::QPropertyEditorDelegate::drawDecoration(), and paint().
00618 { 00619 if (pixmap.isNull() || !rect.isValid()) 00620 return; 00621 QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, 00622 pixmap.size(), rect).topLeft(); 00623 if (option.state & QStyle::State_Selected) { 00624 QPixmap *pm = selected(pixmap, option.palette, option.state & QStyle::State_Enabled); 00625 painter->drawPixmap(p, *pm); 00626 } else { 00627 painter->drawPixmap(p, pixmap); 00628 } 00629 }
Here is the call graph for this function:

| void QItemDelegate::drawFocus | ( | QPainter * | painter, | |
| const QStyleOptionViewItem & | option, | |||
| const QRect & | rect | |||
| ) | const [protected, virtual] |
Renders the region within the rectangle specified by rect, indicating that it has the focus, using the given painter and style option.
Definition at line 636 of file qitemdelegate.cpp.
References QPalette::color(), QPalette::Disabled, QStyle::drawPrimitive(), QPalette::Highlight, QRect::isValid(), QPalette::Normal, o, QStyleOption::palette, QStyle::PE_FrameFocusRect, rect(), QStyleOption::state, QStyle::State_Enabled, QStyle::State_HasFocus, QStyle::State_KeyboardFocusChange, QStyle::State_Selected, QApplication::style(), and QPalette::Window.
Referenced by paint().
00639 { 00640 if ((option.state & QStyle::State_HasFocus) == 0 || !rect.isValid()) 00641 return; 00642 QStyleOptionFocusRect o; 00643 o.QStyleOption::operator=(option); 00644 o.rect = rect; 00645 o.state |= QStyle::State_KeyboardFocusChange; 00646 QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) 00647 ? QPalette::Normal : QPalette::Disabled; 00648 o.backgroundColor = option.palette.color(cg, (option.state & QStyle::State_Selected) 00649 ? QPalette::Highlight : QPalette::Window); 00650 QApplication::style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter); 00651 }
Here is the call graph for this function:

| void QItemDelegate::drawCheck | ( | QPainter * | painter, | |
| const QStyleOptionViewItem & | option, | |||
| const QRect & | rect, | |||
| Qt::CheckState | state | |||
| ) | const [protected, virtual] |
Renders a check indicator within the rectangle specified by rect, using the given painter and style option, using the given state.
Definition at line 659 of file qitemdelegate.cpp.
References Qt::Checked, QStyle::drawPrimitive(), QRect::isValid(), Qt::PartiallyChecked, QStyle::PE_IndicatorViewItemCheck, QStyleOption::rect, rect(), QStyleOption::state, QStyle::State_NoChange, QStyle::State_Off, QStyle::State_On, QApplication::style(), and Qt::Unchecked.
Referenced by paint().
00662 { 00663 if (!rect.isValid()) 00664 return; 00665 00666 QStyleOptionViewItem opt(option); 00667 opt.rect = rect; 00668 opt.state = opt.state & ~QStyle::State_HasFocus; 00669 00670 switch (state) { 00671 case Qt::Unchecked: 00672 opt.state |= QStyle::State_Off; 00673 break; 00674 case Qt::PartiallyChecked: 00675 opt.state |= QStyle::State_NoChange; 00676 break; 00677 case Qt::Checked: 00678 opt.state |= QStyle::State_On; 00679 break; 00680 } 00681 00682 QApplication::style()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter); 00683 }
Here is the call graph for this function:

| void QItemDelegate::drawBackground | ( | QPainter * | painter, | |
| const QStyleOptionViewItem & | option, | |||
| const QModelIndex & | index | |||
| ) | const [protected] |
Definition at line 692 of file qitemdelegate.cpp.
References Qt::BackgroundRole, QPalette::brush(), QPainter::brushOrigin(), QPalette::Disabled, QPainter::fillRect(), QPalette::Highlight, QPalette::Inactive, index, QPalette::Normal, QStyleOption::palette, QStyleOption::rect, QPainter::setBrushOrigin(), QStyleOptionViewItem::showDecorationSelected, QStyleOption::state, QStyle::State_Active, QStyle::State_Enabled, QStyle::State_Selected, QRect::topLeft(), and value.
Referenced by paint().
00695 { 00696 if (option.showDecorationSelected && (option.state & QStyle::State_Selected)) { 00697 QPalette::ColorGroup cg = option.state & QStyle::State_Enabled 00698 ? QPalette::Normal : QPalette::Disabled; 00699 if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) 00700 cg = QPalette::Inactive; 00701 00702 painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight)); 00703 } else { 00704 QVariant value = index.data(Qt::BackgroundRole); 00705 if (qVariantCanConvert<QBrush>(value)) { 00706 QPointF oldBO = painter->brushOrigin(); 00707 painter->setBrushOrigin(option.rect.topLeft()); 00708 painter->fillRect(option.rect, qvariant_cast<QBrush>(value)); 00709 painter->setBrushOrigin(oldBO); 00710 } 00711 } 00712 }
Here is the call graph for this function:

| void QItemDelegate::doLayout | ( | const QStyleOptionViewItem & | option, | |
| QRect * | checkRect, | |||
| QRect * | iconRect, | |||
| QRect * | textRect, | |||
| bool | hint | |||
| ) | const [protected] |
Definition at line 719 of file qitemdelegate.cpp.
References QRect::adjust(), Qt::AlignCenter, QStyle::alignedRect(), QStyleOptionViewItem::Bottom, QSize::boundedTo(), check(), decoration(), QStyleOptionViewItem::decorationAlignment, QStyleOptionViewItem::decorationPosition, QStyleOption::direction, QStyleOptionViewItem::displayAlignment, QStyleOption::fontMetrics, h, QRect::height(), QSize::height(), QSize::isEmpty(), QRect::isEmpty(), QRect::isValid(), QRect::left(), QStyleOptionViewItem::Left, Qt::LeftToRight, QFontMetrics::lineSpacing(), QStyle::pixelMetric(), QStyle::PM_FocusFrameHMargin, qMax(), qWarning(), QStyleOption::rect, QStyleOptionViewItem::Right, QRect::right(), Qt::RightToLeft, QSize::rwidth(), QSize::setHeight(), QRect::setHeight(), QRect::setRect(), QStyleOptionViewItem::showDecorationSelected, QRect::size(), QApplication::style(), QRect::top(), QStyleOptionViewItem::Top, w, QRect::width(), QSize::width(), x, and y.
Referenced by paint(), sizeHint(), and updateEditorGeometry().
00722 { 00723 Q_ASSERT(checkRect && pixmapRect && textRect); 00724 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; 00725 int x = option.rect.left(); 00726 int y = option.rect.top(); 00727 int w, h; 00728 00729 textRect->adjust(-textMargin, 0, textMargin, 0); // add width padding 00730 if (textRect->height() == 0) 00731 textRect->setHeight(option.fontMetrics.lineSpacing()); 00732 00733 QSize pm(0, 0); 00734 if (pixmapRect->isValid()) { 00735 pm = pixmapRect->size(); 00736 pm.rwidth() += 2 * textMargin; 00737 } 00738 if (hint) { 00739 h = qMax(checkRect->height(), qMax(textRect->height(), pm.height())); 00740 if (option.decorationPosition == QStyleOptionViewItem::Left 00741 || option.decorationPosition == QStyleOptionViewItem::Right) { 00742 w = textRect->width() + pm.width(); 00743 } else { 00744 w = qMax(textRect->width(), pm.width()); 00745 } 00746 } else { 00747 w = option.rect.width(); 00748 h = option.rect.height(); 00749 } 00750 00751 int cw = 0; 00752 QRect check; 00753 if (checkRect->isValid()) { 00754 cw = checkRect->width() + 2 * textMargin; 00755 if (hint) w += cw; 00756 if (option.direction == Qt::RightToLeft) { 00757 check.setRect(x + w - cw, y, cw, h); 00758 } else { 00759 check.setRect(x, y, cw, h); 00760 } 00761 } 00762 00763 // at this point w should be the *total* width 00764 00765 QRect display; 00766 QRect decoration; 00767 switch (option.decorationPosition) { 00768 case QStyleOptionViewItem::Top: { 00769 if (!pm.isEmpty()) 00770 pm.setHeight(pm.height() + textMargin); // add space 00771 h = hint ? textRect->height() : h - pm.height(); 00772 00773 if (option.direction == Qt::RightToLeft) { 00774 decoration.setRect(x, y, w - cw, pm.height()); 00775 display.setRect(x, y + pm.height(), w - cw, h); 00776 } else { 00777 decoration.setRect(x + cw, y, w - cw, pm.height()); 00778 display.setRect(x + cw, y + pm.height(), w - cw, h); 00779 } 00780 break; } 00781 case QStyleOptionViewItem::Bottom: { 00782 if (!textRect->isEmpty()) 00783 textRect->setHeight(textRect->height() + textMargin); // add space 00784 h = hint ? textRect->height() + pm.height() : h; 00785 00786 if (option.direction == Qt::RightToLeft) { 00787 display.setRect(x, y, w - cw, textRect->height()); 00788 decoration.setRect(x, y + textRect->height(), w - cw, h - textRect->height()); 00789 } else { 00790 display.setRect(x + cw, y, w - cw, textRect->height()); 00791 decoration.setRect(x + cw, y + textRect->height(), w - cw, h - textRect->height()); 00792 } 00793 break; } 00794 case QStyleOptionViewItem::Left: { 00795 if (option.direction == Qt::LeftToRight) { 00796 decoration.setRect(x + cw, y, pm.width(), h); 00797 display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h); 00798 } else { 00799 display.setRect(x, y, w - pm.width() - cw, h); 00800 decoration.setRect(display.right() + 1, y, pm.width(), h); 00801 } 00802 break; } 00803 case QStyleOptionViewItem::Right: { 00804 if (option.direction == Qt::LeftToRight) { 00805 display.setRect(x + cw, y, w - pm.width() - cw, h); 00806 decoration.setRect(display.right() + 1, y, pm.width(), h); 00807 } else { 00808 decoration.setRect(x, y, pm.width(), h); 00809 display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h); 00810 } 00811 break; } 00812 default: 00813 qWarning("doLayout: decoration position is invalid"); 00814 decoration = *pixmapRect; 00815 break; 00816 } 00817 00818 if (!hint) { // we only need to do the internal layout if we are going to paint 00819 *checkRect = QStyle::alignedRect(option.direction, Qt::AlignCenter, 00820 checkRect->size(), check); 00821 *pixmapRect = QStyle::alignedRect(option.direction, option.decorationAlignment, 00822 pixmapRect->size(), decoration); 00823 // the text takes up all awailable space, unless the decoration is not shown as selected 00824 if (option.showDecorationSelected) 00825 *textRect = display; 00826 else 00827 *textRect = QStyle::alignedRect(option.direction, option.displayAlignment, 00828 textRect->size().boundedTo(display.size()), display); 00829 } else { 00830 *checkRect = check; 00831 *pixmapRect = decoration; 00832 *textRect = display; 00833 } 00834 }
Here is the call graph for this function:

| QRect QItemDelegate::rect | ( | const QStyleOptionViewItem & | option, | |
| const QModelIndex & | index, | |||
| int | role | |||
| ) | const [protected] |
Definition at line 912 of file qitemdelegate.cpp.
References QIcon::actualSize(), check(), Qt::CheckStateRole, QVariant::Color, d, Qt::FontRole, QVariant::Icon, QVariant::Image, index, QVariant::Invalid, QVariant::Pixmap, QStyleOption::rect, QItemDelegatePrivate::replaceNewLine(), size, QVariant::String, textRectangle(), and value.
Referenced by VariantDelegate::displayText(), drawCheck(), qdesigner_internal::QPropertyEditorDelegate::drawDecoration(), drawDecoration(), drawDisplay(), drawFocus(), QCalendarDelegate::paint(), QCalendarDelegate::paintCell(), sizeHint(), and textRectangle().
00914 { 00915 Q_D(const QItemDelegate); 00916 QVariant value = index.data(role); 00917 if (role == Qt::CheckStateRole) 00918 return check(option, option.rect, value); 00919 if (value.isValid()) { 00920 switch (value.type()) { 00921 case QVariant::Invalid: 00922 break; 00923 case QVariant::Pixmap: 00924 return QRect(QPoint(0, 0), qvariant_cast<QPixmap>(value).size()); 00925 case QVariant::Image: 00926 return QRect(QPoint(0, 0), qvariant_cast<QImage>(value).size()); 00927 case QVariant::Icon: { 00928 QIcon::Mode mode = d->iconMode(option.state); 00929 QIcon::State state = d->iconState(option.state); 00930 QIcon icon = qvariant_cast<QIcon>(value); 00931 QSize size = icon.actualSize(option.decorationSize, mode, state); 00932 return QRect(QPoint(0, 0), size); } 00933 case QVariant::Color: 00934 return QRect(QPoint(0, 0), option.decorationSize); 00935 case QVariant::String: 00936 default: { 00937 QString text = QItemDelegatePrivate::replaceNewLine(value.toString()); 00938 value = index.data(Qt::FontRole); 00939 QFont fnt = qvariant_cast<QFont>(value).resolve(option.font); 00940 return textRectangle(0, d->textLayoutBounds(option), fnt, text); } 00941 } 00942 } 00943 return QRect(); 00944 }
Here is the call graph for this function:

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.
Reimplemented from QObject.
Definition at line 1005 of file qitemdelegate.cpp.
References QApplication::activeModalWidget(), QAbstractItemDelegate::closeEditor(), QAbstractItemDelegate::commitData(), QAbstractItemDelegate::EditNextItem, QAbstractItemDelegate::EditPreviousItem, emit, QObject::event(), QEvent::FocusOut, QApplication::focusWidget(), QMetaObject::invokeMethod(), QWidget::isActiveWindow(), key, Qt::Key_Backtab, Qt::Key_Enter, Qt::Key_Escape, Qt::Key_Return, Qt::Key_Tab, QEvent::KeyPress, QAbstractItemDelegate::NoHint, object, QWidget::parentWidget(), Q_ARG, qobject_cast< QWidget * >(), Qt::QueuedConnection, QAbstractItemDelegate::RevertModelCache, QDragManager::self(), QWidget::setFocus(), and w.
Referenced by qdesigner_internal::QPropertyEditorDelegate::eventFilter().
01006 { 01007 QWidget *editor = ::qobject_cast<QWidget*>(object); 01008 if (!editor) 01009 return false; 01010 if (event->type() == QEvent::KeyPress) { 01011 switch (static_cast<QKeyEvent *>(event)->key()) { 01012 case Qt::Key_Tab: 01013 emit commitData(editor); 01014 emit closeEditor(editor, QAbstractItemDelegate::EditNextItem); 01015 return true; 01016 case Qt::Key_Backtab: 01017 emit commitData(editor); 01018 emit closeEditor(editor, QAbstractItemDelegate::EditPreviousItem); 01019 return true; 01020 case Qt::Key_Enter: 01021 case Qt::Key_Return: 01022 // We want the editor to be able to process the key press 01023 // before committing the data (e.g. so it can do 01024 // validation/fixup of the input). 01025 QMetaObject::invokeMethod(this, "_q_commitDataAndCloseEditor", 01026 Qt::QueuedConnection, Q_ARG(QWidget*, editor)); 01027 return false; 01028 case Qt::Key_Escape: 01029 // don't commit data 01030 emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache); 01031 break; 01032 default: 01033 return false; 01034 } 01035 if (editor->parentWidget()) 01036 editor->parentWidget()->setFocus(); 01037 return true; 01038 } else if (event->type() == QEvent::FocusOut) { 01039 if (!editor->isActiveWindow() || (QApplication::focusWidget() != editor)) { 01040 QWidget *w = QApplication::focusWidget(); 01041 while (w) { // don't worry about focus changes internally in the editor 01042 if (w == editor) 01043 return false; 01044 w = w->parentWidget(); 01045 } 01046 #ifndef QT_NO_DRAGANDDROP 01047 // The window may lose focus during an drag operation. 01048 // i.e when dragging involves the taskbar on Windows. 01049 if (QDragManager::self() && QDragManager::self()->object != 0) 01050 return false; 01051 #endif 01052 // Opening a modal dialog will start a new eventloop 01053 // that will process the deleteLater event. 01054 if (QApplication::activeModalWidget() && !QApplication::activeModalWidget()->isAncestorOf(editor)) 01055 return false; 01056 emit commitData(editor); 01057 emit closeEditor(editor, NoHint); 01058 } 01059 } 01060 return false; 01061 }
Here is the call graph for this function:

| bool QItemDelegate::editorEvent | ( | QEvent * | event, | |
| QAbstractItemModel * | model, | |||
| const QStyleOptionViewItem & | option, | |||
| const QModelIndex & | index | |||
| ) | [protected, virtual] |
Reimplemented from QAbstractItemDelegate.
Definition at line 1067 of file qitemdelegate.cpp.
References QStyle::alignedRect(), Qt::AlignLeft, Qt::AlignVCenter, check(), Qt::Checked, Qt::CheckStateRole, QRect::contains(), QStyleOption::direction, QObject::event(), QAbstractItemModel::flags(), flags, QRect::height(), index, Qt::ItemIsEnabled, Qt::ItemIsUserCheckable, key, Qt::Key_Select, Qt::Key_Space, QEvent::KeyPress, QEvent::MouseButtonDblClick, QEvent::MouseButtonRelease, QStyle::pixelMetric(), QStyle::PM_FocusFrameHMargin, QStyleOption::rect, QAbstractItemModel::setData(), QRect::size(), QApplication::style(), Qt::Unchecked, value, QRect::width(), QRect::x(), and QRect::y().
01071 { 01072 Q_ASSERT(event); 01073 Q_ASSERT(model); 01074 01075 // make sure that the item is checkable 01076 Qt::ItemFlags flags = model->flags(index); 01077 if (!(flags & Qt::ItemIsUserCheckable) || !((flags & Qt::ItemIsEnabled))) 01078 return false; 01079 01080 // make sure that we have a check state 01081 QVariant value = index.data(Qt::CheckStateRole); 01082 if (!value.isValid()) 01083 return false; 01084 01085 // make sure that we have the right event type 01086 if ((event->type() == QEvent::MouseButtonRelease) 01087 || (event->type() == QEvent::MouseButtonDblClick)) { 01088 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; 01089 QRect checkRect = QStyle::alignedRect(option.direction, Qt::AlignLeft | Qt::AlignVCenter, 01090 check(option, option.rect, Qt::Checked).size(), 01091 QRect(option.rect.x() + textMargin, option.rect.y(), 01092 option.rect.width(), option.rect.height())); 01093 if (!checkRect.contains(static_cast<QMouseEvent*>(event)->pos())) 01094 return false; 01095 01096 // eat the double click events inside the check rect 01097 if (event->type() == QEvent::MouseButtonDblClick) 01098 return true; 01099 01100 } else if (event->type() == QEvent::KeyPress) { 01101 if (static_cast<QKeyEvent*>(event)->key() != Qt::Key_Space 01102 && static_cast<QKeyEvent*>(event)->key() != Qt::Key_Select) 01103 return false; 01104 } else { 01105 return false; 01106 } 01107 01108 Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked 01109 ? Qt::Unchecked : Qt::Checked); 01110 return model->setData(index, state, Qt::CheckStateRole); 01111 }
Here is the call graph for this function:

| QStyleOptionViewItem QItemDelegate::setOptions | ( | const QModelIndex & | index, | |
| const QStyleOptionViewItem & | option | |||
| ) | const [protected] |
Definition at line 1117 of file qitemdelegate.cpp.
References QStyleOptionViewItem::displayAlignment, QStyleOptionViewItem::font, QStyleOption::fontMetrics, Qt::FontRole, Qt::ForegroundRole, index, QStyleOption::palette, QFont::resolve(), QPalette::setBrush(), QPalette::Text, Qt::TextAlignmentRole, and value.
Referenced by paint().
01119 { 01120 QStyleOptionViewItem opt = option; 01121 01122 // set font 01123 QVariant value = index.data(Qt::FontRole); 01124 if (value.isValid()){ 01125 opt.font = qvariant_cast<QFont>(value).resolve(opt.font); 01126 opt.fontMetrics = QFontMetrics(opt.font); 01127 } 01128 01129 // set text alignment 01130 value = index.data(Qt::TextAlignmentRole); 01131 if (value.isValid()) 01132 opt.displayAlignment = (Qt::Alignment)value.toInt(); 01133 01134 // set foreground brush 01135 value = index.data(Qt::ForegroundRole); 01136 if (qVariantCanConvert<QBrush>(value)) 01137 opt.palette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value)); 01138 01139 return opt; 01140 }
Here is the call graph for this function:

| QPixmap QItemDelegate::decoration | ( | const QStyleOptionViewItem & | option, | |
| const QVariant & | variant | |||
| ) | const [protected] |
Definition at line 844 of file qitemdelegate.cpp.
References QVariant::Color, d, QStyleOptionViewItem::decorationSize, QPixmap::fill(), QVariant::Icon, QStyleOption::state, and variant.
Referenced by doLayout(), paint(), and updateEditorGeometry().
00845 { 00846 Q_D(const QItemDelegate); 00847 switch (variant.type()) { 00848 case QVariant::Icon: { 00849 QIcon::Mode mode = d->iconMode(option.state); 00850 QIcon::State state = d->iconState(option.state); 00851 return qvariant_cast<QIcon>(variant).pixmap(option.decorationSize, mode, state); } 00852 case QVariant::Color: { 00853 static QPixmap pixmap(option.decorationSize); 00854 pixmap.fill(qvariant_cast<QColor>(variant)); 00855 return pixmap; } 00856 default: 00857 break; 00858 } 00859 00860 return qvariant_cast<QPixmap>(variant); 00861 }
Here is the call graph for this function:

| QPixmap * QItemDelegate::selected | ( | const QPixmap & | pixmap, | |
| const QPalette & | palette, | |||
| bool | enabled | |||
| ) | const [protected] |
Definition at line 885 of file qitemdelegate.cpp.
References QPainter::CompositionMode_SourceAtop, QImage::convertToFormat(), QPalette::Disabled, QPainter::end(), QPainter::fillRect(), QPixmapCache::find(), QImage::Format_ARGB32_Premultiplied, QPixmap::fromImage(), QImage::height(), QPalette::Highlight, QPixmapCache::insert(), key, QPalette::Normal, palette, qPixmapSerial(), qt_pixmap_id(), QColor::setAlphaF(), QPainter::setCompositionMode(), QPixmap::toImage(), and QImage::width().
Referenced by drawDecoration().
00886 { 00887 QString key = qPixmapSerial(qt_pixmap_id(pixmap), enabled); 00888 QPixmap *pm = QPixmapCache::find(key); 00889 if (!pm) { 00890 QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); 00891 00892 QColor color = palette.color(enabled ? QPalette::Normal : QPalette::Disabled, 00893 QPalette::Highlight); 00894 color.setAlphaF(0.3); 00895 00896 QPainter painter(&img); 00897 painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); 00898 painter.fillRect(0, 0, img.width(), img.height(), color); 00899 painter.end(); 00900 00901 QPixmap selected = QPixmap(QPixmap::fromImage(img)); 00902 QPixmapCache::insert(key, selected); 00903 pm = QPixmapCache::find(key); 00904 } 00905 return pm; 00906 }
Here is the call graph for this function:

| QRect QItemDelegate::check | ( | const QStyleOptionViewItem & | option, | |
| const QRect & | bounding, | |||
| const QVariant & | variant | |||
| ) | const [protected] |
Definition at line 949 of file qitemdelegate.cpp.
References QStyle::SE_ViewItemCheckIndicator, QApplication::style(), QStyle::subElementRect(), and value.
Referenced by doLayout(), editorEvent(), paint(), rect(), and updateEditorGeometry().
00951 { 00952 if (value.isValid()) { 00953 QStyleOptionButton opt; 00954 opt.QStyleOption::operator=(option); 00955 opt.rect = bounding; 00956 return QApplication::style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt); 00957 } 00958 return QRect(); 00959 }
Here is the call graph for this function:

| QRect QItemDelegate::textRectangle | ( | QPainter * | painter, | |
| const QRect & | rect, | |||
| const QFont & | font, | |||
| const QString & | text | |||
| ) | const [protected] |
Definition at line 964 of file qitemdelegate.cpp.
References d, QStyle::pixelMetric(), QStyle::PM_FocusFrameHMargin, rect(), QItemDelegatePrivate::replaceNewLine(), size, QApplication::style(), QRect::width(), and QTextOption::WordWrap.
Referenced by paint(), rect(), and updateEditorGeometry().
00966 { 00967 Q_D(const QItemDelegate); 00968 d->textOption.setWrapMode(QTextOption::WordWrap); 00969 d->textLayout.setTextOption(d->textOption); 00970 d->textLayout.setFont(font); 00971 d->textLayout.setText(QItemDelegatePrivate::replaceNewLine(text)); 00972 const QSize size = d->doTextLayout(rect.width()).toSize(); 00973 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; 00974 return QRect(0, 0, size.width() + 2 * textMargin, size.height()); 00975 }
Here is the call graph for this function:

1.5.1