ItemDelegate
::ItemDelegate(QObject *parent
) :{
_currRow = -1;
}
void ItemDelegate
::paint ( QPainter* painter,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
if (!index.isValid())
return;
...
button.rect = buttonRect;
if(_currRow == index.row())
button.
state = QStyle::State_Sunken |
QStyle::State_Enabled;
else
button.
state = QStyle::State_Raised |
QStyle::State_Enabled;
}
{
Q_UNUSED(model)
if( event
->type
() != QEvent::MouseButtonPress && event
->type
() != QEvent::MouseButtonRelease ) { return true;
}
if( event
->type
() == QEvent::MouseButtonPress) _currRow = index.row();
else
_currRow = -1;
...
QMouseEvent* mouseEvent
= static_cast<QMouseEvent
*>
(event
);
if( !buttonRect.contains( mouseEvent->pos()) ) {
return true;
}
if( event
->type
() == QEvent::MouseButtonRelease) { // call slot
}
return true;
}
ItemDelegate::ItemDelegate(QObject *parent) :
QAbstractItemDelegate(parent)
{
_currRow = -1;
}
void ItemDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
if (!index.isValid())
return;
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0);
...
QStyleOptionButton button;
button.rect = buttonRect;
button.features |= QStyleOptionButton::Flat;
if(_currRow == index.row())
button.state = QStyle::State_Sunken | QStyle::State_Enabled;
else
button.state = QStyle::State_Raised | QStyle::State_Enabled;
QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
}
bool ItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
Q_UNUSED(model)
if( event->type() != QEvent::MouseButtonPress &&
event->type() != QEvent::MouseButtonRelease ) {
return true;
}
if( event->type() == QEvent::MouseButtonPress)
_currRow = index.row();
else
_currRow = -1;
...
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
if( !buttonRect.contains( mouseEvent->pos()) ) {
return true;
}
if( event->type() == QEvent::MouseButtonRelease) {
// call slot
}
return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks