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. Implementing hover

Implementing hover

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 568 Views
  • 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
    mahd96
    wrote on last edited by
    #1

    i need to activate hover or implement it whitin PaintEvent() .
    i can not use StyleSheet.

    how can i do it?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      You need to subclass and override enterEvent/leaveEvent
      Then you can use a variable to know if you been hovered and paint differently in paintEvent.

      
      class Label : public QLabel {
        Q_OBJECT
      public:
        Label(QWidget* parent = Q_NULLPTR) :QLabel("test", parent) {}  
      protected:  
        virtual void enterEvent(QEvent* event) override {
          event->accept();
          qDebug() << "enterEvent" << objectName();
        }
        virtual void leaveEvent(QEvent* event) override {
          event->accept();
        }
      };
      
      

      Notice, i used Label here. you might want plain QWidget instead.

      1 Reply Last reply
      4
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        Answer above is more flexible, but may be overkill if your need to hover is more trivial (like displaying tool tip text), then you can simply set the setToolTip(Qstring) for each widget where you want a tip to pop up on hover. See

        QWidget::setToolTip(QString& str)
        QWidget::setToolTipDuration(int msec)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mahd96
          wrote on last edited by mahd96
          #4

          i used in "underMouse()" in paintEvent(). with WA_Hover attribute set.
          it works as i need.

          1 Reply Last reply
          1

          • Login

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