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. Hover Event - 2 windows
Qt 6.11 is out! See what's new in the release blog

Hover Event - 2 windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 2 Posters 802 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.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by
    #5

    @SGaist But how? I see here 1 problem:

    In this method ( widgetAt ) I need QPoint. I can do something like:

    In hoverLeave method:
    auto wid = QApplication::widgetAt(QCursor::pos());
    

    I don't see any other method to get QPoint - only from QCursor::pos(). Event->pos() give me QPoint(-1,-1).

    So QCursor::pos(). But this is bad solution because when I do very fast move my mouse I get strange position.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      Which hoverLeave method ?

      What about QWidget::leaveEvent ?

      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
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #7

        @SGaist hoverLeave method is my method which is execute when there is QHoverEvent. I think in this example QWidget::leaveEvent and QHoverEvent are very simillar.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #8

          Then please show your code.

          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
          • T Offline
            T Offline
            TomNow99
            wrote on last edited by TomNow99
            #9

            @SGaist I don't have it on thic pc, so I can only give you some pseudoCode:

            bool MainWindow::event(QEvent * e)
            {
                switch(e->type())
                {
                case QEvent::HoverEnter:
                    hoverEnter(static_cast<QHoverEvent*>(e));
                    return true;
                    break;
                case QEvent::HoverLeave:
                    hoverLeave(static_cast<QHoverEvent*>(e));
                    return true;
                    break;
                default:
                    break;
                }
                return QWidget::event(e);
            }
            
            void MainWindow::hoverEnter(QHoverEvent * event) 
            {
                 if( !label -> isVisible() )
                 {
                      label->show();
                 }
            }
            void MainWindow::hoverLeave(QHoverEvent * event) 
            {
                 if( label -> isVisible )
                 {
                      label->hide();
                 }
            }
            
            

            EDIT:
            I have while(true) here :) When I have cursor in label I have loop:
            hide->show->hide->show->hide->...

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #10

              Why a while ? You will only manage to block the event loop.

              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
              1
              • T Offline
                T Offline
                TomNow99
                wrote on last edited by
                #11

                @SGaist Could you give me some snippet - I don't do this before

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  A snippet of what ?

                  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
                  • T Offline
                    T Offline
                    TomNow99
                    wrote on last edited by
                    #13

                    @SGaist Blocking event loop

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      You do not want to block the event loop. That will freeze your GUI.

                      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
                      • T Offline
                        T Offline
                        TomNow99
                        wrote on last edited by
                        #15

                        @SGaist Now in functions hoverEnter and hoverLeave I do:

                        qInfo()<<"enter"; 
                        or
                        qInfo()<<"leave"; 
                        

                        When my mouse cursor is in place, where label is I see in QT words:
                        enter, leave, enter, leave, enter, leave, enter, leave, enter, leave, enter, leave, enter, leave, enter, leave, ...

                        And I see that my label is hidden -> shown ->hidden -> shown ->hidden -> shown ->hidden -> shown ->hidden -> shown ->hidden -> shown ->...

                        How can I do what I want ( picture ) ?

                        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