Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED-kinda] QStylesheet - hover get stuck when using setVisible(false)

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    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


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #2

      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;
      

      }
      @


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved