2
votes

I am writing a Qt application for CentOS using Qt5.5.1.

void mouseReleaseEvent (QMouseEvent * event)
{
   setCursor (Qt::ArrowCursor); //Reset to default arrow cursor.
}

void mousePressEvent (QMouseEvent * event)
{
   setCursor (QCursor (QPixmap (":/Drag_and_Drop_bubble.png"))); //Customized cursor. This works well when set inside constructor (during initialization).
}

Requirement: I want the cursor to change on the press of the mouse left-click. The cursor should remain until mouse click is released. As soon as the mouse click is release, the cursor should be reset to default cursor.

Problem Statement: The cursor does not change on the click of mouse left button. It only changes after I release the left click [To verify this: I commented setCursor() function inside mouseReleaseEvent()]. Why does the cursor not change after mouse left-click and before click release? Any one encountered such issue?

Thank you for the help.

1
Could not replicate the issue myself. Make sure that Drag_and_Drop_bubble.png is available in the resources. Did you try using a predefined cursor such as Qt::PointingHandCursor? Could you post the minimal reproducible example?Meliodas
@Meliodas I was accessing the machine remotely via VNC Viewer. The bubble cursor appears if I use the mouse on the machine directly (no remote), and also appears using touching monitor of HMI (working on touch monitor). The issue now is due to VNC because the VNC does not show the cursor is updated to bubble cursor. It only shows when mouseReleaseEvent() is triggered.pkthapa
@Meliodas The Drag_and_Drop_bubble.png resource is available correctly because the same is displayed on mouseReleaseEvent() trigger. The bubble cursor also appears on the monitor when I access via VNC, but the same bubble cursor is not seen on VNC Viewer.pkthapa

1 Answers

0
votes

It could be that it doesn't update the ui immediately. I've had this in the past.

try this:

void mouseReleaseEvent (QMouseEvent * event)
{
   setCursor (Qt::ArrowCursor); //Reset to default arrow cursor.
   this->update();         
}

void mousePressEvent (QMouseEvent * event)
{
   setCursor (QCursor (QPixmap (":/Drag_and_Drop_bubble.png"))); //Customized cursor. This works well when set inside constructor (during initialization).
}

If it doesn't work, what is your class derived from? (this way I can try to recreate these functions)