Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Change cursor does not work when move mouse from outside of QWidget



  • #include "widget.h"
    #include "ui_widget.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
        ui->widget->setCursor(QCursor(Qt::PointingHandCursor));
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    void Widget::resizeEvent(QResizeEvent *event){
        ui->widget->setGeometry(0, this->size().height()-50, this->size().width(),50);
    }
    
    

    If I move mose from upper part of main widget into the lower part, the cursor changed to a hand
    But if I move mouse from outside of main widget into the lwoer part, the cursor won't change to a hand most time
    why, and how can I fix this



  • @pengxu
    I would look at reimplementing your Widgets hover events, mousemove events, enter/leaveEvents or even event/eventFilter to set your cursor, if you are finding provlems with what you have now. For hover events, at least, you could also implement your desired cursor via stylesheet, which may work better than what you have now in code.


Log in to reply