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. How to change QPushButton hover area?
Forum Updated to NodeBB v4.3 + New Features

How to change QPushButton hover area?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 522 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.
  • Q Offline
    Q Offline
    qwe3
    wrote on 4 Jan 2022, 09:37 last edited by
    #1

    Hi,

    I have a QPushButton ( or class which inherits QPushButton ) and I set a new style for this button using setStyleSheet(). I set for example margin and QPushButton:hover section ( color etc. ).

    When my mouse cursor is on the margin area, hover is activated. I would like to decrease hover area. Hover can't be on margin section.

    I know that I can change click area using QAbstractButton::hitButton() and I would like to do the same with hover.

    I tried with eventFilter() like this:

    bool MyButton::eventFilter(QObject *obj, QEvent *event){
        auto eventType = event->type();
    
        if( eventType == QEvent::HoverEnter || eventType == QEvent::HoverMove ){
            auto hoverEv = static_cast<QHoverEvent *>(event);
            QRect newRect = QRect(0,0,50,50);
            if( !newRect.contains(hoverEv->pos()) ){
                return true;
            }
        }
    
        return QWidget::eventFilter(obj, event);
    }
    

    And the problem is:
    button.png

    I have mouse cursor in red X position. Now I move mouse cursor up. And in yellow circle point I get hover enter event. I check if my blue rectangle ( 0,0,100,100 ) contains that yellow circle point. No. So I do nothing with that event. Next I move cursor left-up and in orange circle point I don't get hover enter event. I would like to get it here.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Jan 2022, 17:03 last edited by
      #2

      Hi,

      There's no "move the hover entry points" concept applicable. What you could do is generate a synthetic event or use an overlay widget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      4 Jan 2022, 09:37

      • Login

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