void MyDelegate
::paint(QPainter *painter,
{
Q_ASSERT(model);
if (qVariantCanConvert<MyCustomsClass>(index.data(MyModel::DeviceInfoRole)))
{
MyCustomsClass info = qVariantValue<MyCustomsClass>(index.data(MyModel::DeviceInfoRole));
buttonOption.state = option.state;
#ifdef Q_WS_MAC
buttonOption.
state |
= QStyle::State_Raised;
#endif
buttonOption.
state &= ~
QStyle::State_HasFocus;
buttonOption.rect = option.rect ;
buttonOption.palette = option.palette;
m_view
->style
()->drawControl
(QStyle::CE_PushButton,
&buttonOption, painter, m_view
);
static const int i = 9; // ### hardcoded in qcommonstyle.cpp
branchOption.
rect = QRect(r.
left() + i
/2, r.
top() + (r.
height() - i
)/2, i, i
);
branchOption.palette = option.palette;
branchOption.
state = QStyle::State_Children;
// draw text
QRect textrect
= QRect(r.
left() + i
*2, r.
top(), r.
width() - ((5*i
)/2), r.
height());
QString text
= elidedText
(option.
fontMetrics, textrect.
width(), Qt
::ElideMiddle,
info .name());
m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter,
option.palette, m_view->isEnabled(), text);
}
}