Mouse Cursor reset problem
-
wrote on 25 Mar 2012, 21:20 last edited by
i have item delegate that when the mouse event is over icon i change its Cursor to Qt::PointingHandCursor
when its off i set it back to Qt::ArrowCursor . its working fine .
the problem is that besides when it over the icon . it allways stack on Qt::ArrowCursor
even in situation when the icon needs to changes nativly like when resizing the windows or when over native push button . it always Qt::ArrowCursor.
how can i force the Cursor act normally when its is no over the icon?
here is what i do :
@
bool MiniItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option,
const QModelIndex &index)
{
// Emit a signal when the icon is clicked
QMouseEvent mouseEvent = static_cast<QMouseEvent>(event);
if(!index.parent().isValid() && event->type() == QEvent::MouseMove)
{
QSize iconsize = m_iconAdd.actualSize(option.decorationSize);
QRect closeButtonRect = m_iconAdd.pixmap(iconsize.width(),iconsize.height())
.rect().translated(AddIconPos(option));QSize iconRemoveSize = m_iconRemove.actualSize(option.decorationSize); QRect iconRemoveRect = m_iconRemove.pixmap(iconRemoveSize.width(), iconRemoveSize.height()) .rect().translated(RemoveIconPos(option)); if(closeButtonRect.contains(mouseEvent->pos())) { QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); } else if(iconRemoveRect.contains(mouseEvent->pos())) { QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); } else { Qt::CursorShape shape = Qt::ArrowCursor; QApplication::setOverrideCursor(QCursor(shape)); } } if(!index.parent().isValid() && event->type() == QEvent::MouseButtonRelease) { QSize iconsize = m_iconAdd.actualSize(option.decorationSize); QRect closeButtonRect = m_iconAdd.pixmap(iconsize.width(),iconsize.height()) .rect().translated(AddIconPos(option)); QSize iconRemoveSize = m_iconRemove.actualSize(option.decorationSize); QRect iconRemoveRect = m_iconRemove.pixmap(iconRemoveSize.width(),iconRemoveSize.height()) .rect().translated(RemoveIconPos(option)); if(closeButtonRect.contains(mouseEvent->pos())) { ; } else if(iconRemoveRect.contains(mouseEvent->pos())) { ; } } return false;
}
@ -
wrote on 26 Mar 2012, 21:35 last edited by
Which widget are you using with your delegate ?
-
wrote on 26 Mar 2012, 21:42 last edited by
QStyledItemDelegate with QTableView
-
wrote on 26 Mar 2012, 21:45 last edited by
I mean widgets for cell editing.
Could you make a screenshot ? -
wrote on 26 Mar 2012, 22:17 last edited by
what widgets ? i dont understand
im using simple icon images -
wrote on 27 Mar 2012, 18:41 last edited by
You're probably looking for "restoreOverrideCursor":/doc/qt-4.8/qapplication.html#restoreOverrideCursor to undo the effects of setOverrideCursor.
1/6