bool DownloadItemDelegate::editorEvent(
const QStyleOptionViewItem& option,
{
if (event
->type
() == QEvent::MouseButtonPress) {
if (index.data(Qt::UserRole).toRect().contains(e->pos())) // button "resume"
{
model->setData(index, true, Qt::UserRole + 1); // button pressed (visual-only | button style = sunken)
model->setData(index, true, Qt::UserRole + 2); // button pressed (is clicked?)
return true;
}
}
else if (event
->type
() == QEvent::MouseButtonRelease) {
if (index.data(Qt::UserRole).toRect().contains(e->pos()))
{
model->setData(index, false, Qt::UserRole + 1); // button style = enabled
if (index.data(Qt::UserRole + 2).toBool()) // is clicked == true | emit resume();
{
//emit resume_pressed;
}
return true;
}
model->setData(index, false, Qt::UserRole + 2); // clear this flag
}
else if (event
->type
() == QEvent::MouseMove) {
if (!index.data(Qt::UserRole).toRect().contains(e->pos())) // if exit button rect, button style = enabled
{
model->setData(index, false, Qt::UserRole + 1);
return true;
}
else if (index.data(Qt::UserRole + 2).toBool()) // if enter button rect, and, the checked flag is true, button style = sunken
{
model->setData(index, true, Qt::UserRole + 1);
return true;
}
}
return false;
}
bool DownloadItemDelegate::editorEvent(
QEvent* event,
QAbstractItemModel* model,
const QStyleOptionViewItem& option,
const QModelIndex &index)
{
if (event->type() == QEvent::MouseButtonPress)
{
QMouseEvent* e = (QMouseEvent*)event;
if (index.data(Qt::UserRole).toRect().contains(e->pos())) // button "resume"
{
model->setData(index, true, Qt::UserRole + 1); // button pressed (visual-only | button style = sunken)
model->setData(index, true, Qt::UserRole + 2); // button pressed (is clicked?)
return true;
}
}
else if (event->type() == QEvent::MouseButtonRelease)
{
QMouseEvent* e = (QMouseEvent*)event;
if (index.data(Qt::UserRole).toRect().contains(e->pos()))
{
model->setData(index, false, Qt::UserRole + 1); // button style = enabled
if (index.data(Qt::UserRole + 2).toBool()) // is clicked == true | emit resume();
{
//emit resume_pressed;
}
return true;
}
model->setData(index, false, Qt::UserRole + 2); // clear this flag
}
else if (event->type() == QEvent::MouseMove)
{
QMouseEvent* e = (QMouseEvent*)event;
if (!index.data(Qt::UserRole).toRect().contains(e->pos())) // if exit button rect, button style = enabled
{
model->setData(index, false, Qt::UserRole + 1);
return true;
}
else if (index.data(Qt::UserRole + 2).toBool()) // if enter button rect, and, the checked flag is true, button style = sunken
{
model->setData(index, true, Qt::UserRole + 1);
return true;
}
}
return false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks