#include <sheet_delegate_p.h>
Inheritance diagram for qdesigner_internal::SheetDelegate:


Definition at line 48 of file sheet_delegate_p.h.
Public Member Functions | |
| SheetDelegate (QTreeView *view, QWidget *parent) | |
| virtual void | paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| virtual QSize | sizeHint (const QStyleOptionViewItem &opt, const QModelIndex &index) const |
Private Attributes | |
| QTreeView * | m_view |
Definition at line 33 of file sheet_delegate.cpp.
00034 : QItemDelegate(parent), 00035 m_view(view) 00036 { 00037 }
| void qdesigner_internal::SheetDelegate::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.
Reimplemented from QItemDelegate.
Definition at line 39 of file sheet_delegate.cpp.
References Qt::AlignCenter, QStyle::CE_PushButton, QAbstractItemModel::data(), Qt::DisplayRole, QStyle::drawControl(), QStyle::drawItemText(), QStyle::drawPrimitive(), QAbstractItemDelegate::elidedText(), Qt::ElideMiddle, QStyleOption::fontMetrics, QRect::height(), i, index, QWidget::isEnabled(), QTreeView::isExpanded(), QModelIndex::isValid(), QRect::left(), m_view, QStyleOptionButton::None, QItemDelegate::paint(), QStyleOption::palette, QAbstractItemModel::parent(), QStyle::PE_IndicatorBranch, QStyleOption::rect, QStyleOption::state, QStyle::State_Children, QStyle::State_Open, QStyle::State_Raised, QWidget::style(), QRect::top(), QVariant::toString(), and QRect::width().
00040 { 00041 const QAbstractItemModel *model = index.model(); 00042 Q_ASSERT(model); 00043 00044 if (!model->parent(index).isValid()) { 00045 // this is a top-level item. 00046 QStyleOptionButton buttonOption; 00047 00048 buttonOption.state = option.state; 00049 #ifdef Q_WS_MAC 00050 buttonOption.state |= QStyle::State_Raised; 00051 #endif 00052 buttonOption.state &= ~QStyle::State_HasFocus; 00053 00054 buttonOption.rect = option.rect; 00055 buttonOption.palette = option.palette; 00056 buttonOption.features = QStyleOptionButton::None; 00057 m_view->style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter, m_view); 00058 00059 QStyleOption branchOption; 00060 static const int i = 9; // ### hardcoded in qcommonstyle.cpp 00061 QRect r = option.rect; 00062 branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i); 00063 branchOption.palette = option.palette; 00064 branchOption.state = QStyle::State_Children; 00065 00066 if (m_view->isExpanded(index)) 00067 branchOption.state |= QStyle::State_Open; 00068 00069 m_view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, m_view); 00070 00071 // draw text 00072 QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height()); 00073 QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle, 00074 model->data(index, Qt::DisplayRole).toString()); 00075 m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter, 00076 option.palette, m_view->isEnabled(), text); 00077 00078 } else { 00079 QItemDelegate::paint(painter, option, index); 00080 } 00081 }
Here is the call graph for this function:

| QSize qdesigner_internal::SheetDelegate::sizeHint | ( | const QStyleOptionViewItem & | opt, | |
| 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.
Reimplemented from QItemDelegate.
Definition at line 83 of file sheet_delegate.cpp.
References index, and QItemDelegate::sizeHint().
00084 { 00085 QStyleOptionViewItem option = opt; 00086 QSize sz = QItemDelegate::sizeHint(opt, index) + QSize(2, 2); 00087 return sz; 00088 }
Here is the call graph for this function:

1.5.1