rsilva
16th May 2011, 02:10
I'm using this code, but the editorEvent doesn't called in a "leave" event.
And the mouse move don't capture events outside the item rect
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;
}
This handles the basics of a QPushButton that I need, but, how can I check if the mouse leave the item region ?
I need to check this event to clear the flags of the button.
And the mouse move don't capture events outside the item rect
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;
}
This handles the basics of a QPushButton that I need, but, how can I check if the mouse leave the item region ?
I need to check this event to clear the flags of the button.