[SOLVED-kinda] QStylesheet - hover get stuck when using setVisible(false)



  • I have a custom button with this stylesheet (a simple button that change image when hovering on it):
    @QPushButton#pushButton_expand {
    image: url(:/image/icon/exp1);
    border-radius: 1px;
    }

    QPushButton#pushButton_expand:hover {
    image: url(:/image/icon/exp2);
    border-radius: 1px;
    }@

    When I click this button, an event is triggered that change the window appearance and set this button to be invisible. I have another even that show back this button when needed.
    However, when the button is show again, the stylesheet is stuck to "hover" (wrong image is shown).
    I have tried manually setting it's hover state to false and refreshing the widget before setting it to invisible, but not sucessfull

    Here is the method that hide the button, if I just comment the line *6, the problem disapear but I don't want this button visible.. :

    @void TopMenuWorkout::setMinExpandExitVisible(bool visible)
    {
    ui->pushButton_minimize->setVisible(visible);
    // ui->pushButton_expand->setAttribute(Qt::WA_Hover, false);
    // ui->pushButton_expand->update();
    // ui->pushButton_expand->repaint();
    ui->pushButton_expand->setVisible(visible); /// *6 Line to comment
    ui->pushButton_exit->setVisible(visible);
    }@

    If anyone can help me, I've wasted 2hrs trial and error on this, next step i'll try changing the hover image with Event instead of Stylesheet... thanks



  • Damn this I hacked it:

    @bool TopMenuWorkout::eventFilter(QObject *watched, QEvent *event) {

    Q_UNUSED(watched);
    
    qDebug() << "watched object" << watched << "event:" << event << "eventType" << event->type();
    
    if(event->type() == QEvent::HoverEnter)
    {
        ui->pushButton_expand->setStyleSheet("QPushButton#pushButton_expand{image: url(:/image/icon/exp2);border-radius: 1px;}");
    }
    else if(event->type() == QEvent::HoverLeave)
    {
        ui->pushButton_expand->setStyleSheet("QPushButton#pushButton_expand{image: url(:/image/icon/exp1);border-radius: 1px;}");
    }
    return false;
    

    }
    @


Log in to reply
 

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