March 25, 2012

umen242 umen242
Lab Rat
344 posts

Mouse Cursor reset problem

 

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 :

  1. bool MiniItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
  2.            const QStyleOptionViewItem &option,
  3.            const QModelIndex &index)
  4. {
  5.     // Emit a signal when the icon is clicked
  6.     QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
  7.     if(!index.parent().isValid() && event->type() == QEvent::MouseMove)
  8.     {
  9.         QSize  iconsize = m_iconAdd.actualSize(option.decorationSize);
  10.         QRect closeButtonRect =  m_iconAdd.pixmap(iconsize.width(),iconsize.height())
  11.                 .rect().translated(AddIconPos(option));
  12.  
  13.         QSize iconRemoveSize = m_iconRemove.actualSize(option.decorationSize);
  14.         QRect iconRemoveRect =  
  15.                 m_iconRemove.pixmap(iconRemoveSize.width(), iconRemoveSize.height())
  16.                         .rect().translated(RemoveIconPos(option));
  17.      
  18.         if(closeButtonRect.contains(mouseEvent->pos()))
  19.         {                
  20.             QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
  21.         }
  22.         else if(iconRemoveRect.contains(mouseEvent->pos()))
  23.         {
  24.             QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
  25.         }
  26.         else
  27.         {
  28.             Qt::CursorShape shape = Qt::ArrowCursor;
  29.             QApplication::setOverrideCursor(QCursor(shape));
  30.         }
  31.     }
  32.  
  33.     if(!index.parent().isValid() && event->type() == QEvent::MouseButtonRelease)
  34.     {
  35.         QSize  iconsize = m_iconAdd.actualSize(option.decorationSize);
  36.         QRect closeButtonRect =  m_iconAdd.pixmap(iconsize.width(),iconsize.height())
  37.                 .rect().translated(AddIconPos(option));
  38.  
  39.         QSize iconRemoveSize = m_iconRemove.actualSize(option.decorationSize);
  40.         QRect iconRemoveRect =  
  41.                 m_iconRemove.pixmap(iconRemoveSize.width(),iconRemoveSize.height())
  42.                         .rect().translated(RemoveIconPos(option));
  43.    
  44.         if(closeButtonRect.contains(mouseEvent->pos()))
  45.         {
  46.             ;
  47.         }
  48.         else if(iconRemoveRect.contains(mouseEvent->pos()))
  49.         {
  50.             ;
  51.         }
  52.     }
  53.  
  54.     return false;
  55. }

5 replies

March 26, 2012

dridk dridk
Lab Rat
48 posts

Which widget are you using with your delegate ?

 Signature 

Nothing in Biology Makes Sense Except in the Light of Evolution

March 26, 2012

umen242 umen242
Lab Rat
344 posts

QStyledItemDelegate with QTableView

March 26, 2012

dridk dridk
Lab Rat
48 posts

I mean widgets for cell editing.
Could you make a screenshot ?

 Signature 

Nothing in Biology Makes Sense Except in the Light of Evolution

March 27, 2012

umen242 umen242
Lab Rat
344 posts

what widgets ? i dont understand
im using simple icon images

March 27, 2012

mlong mlong
Robot Herder
1551 posts

You’re probably looking for restoreOverrideCursor to undo the effects of setOverrideCursor.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

 
  ‹‹ QTreeWidget - Drag to Resize      [SOLVED] Updating the text on a QLabel ››

You must log in to post a reply. Not a member yet? Register here!