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 :
    @
    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;
    

    }
    @



  • Which widget are you using with your delegate ?



  • QStyledItemDelegate with QTableView



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



  • what widgets ? i dont understand
    im using simple icon images


  • Moderators

    You're probably looking for "restoreOverrideCursor":/doc/qt-4.8/qapplication.html#restoreOverrideCursor to undo the effects of setOverrideCursor.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.